From 5ecfd947e2a1b363cdcb2bb7df730a5e0af3813d Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Mon, 18 Nov 2019 21:45:55 +0200 Subject: [PATCH] test: update and harden http2-reset-flood * use new maxSessionInvalidFrames to lower the needed frames * slow down requests to generate less redundant after-session-close requests PR-URL: https://github.com/nodejs/node/pull/30534 Fixes: https://github.com/nodejs/node/issues/30505 Reviewed-By: Anna Henningsen Reviewed-By: David Carlier Reviewed-By: James M Snell --- test/parallel/test-http2-reset-flood.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-http2-reset-flood.js b/test/parallel/test-http2-reset-flood.js index 9977bfd1a3e669..25520f81f23717 100644 --- a/test/parallel/test-http2-reset-flood.js +++ b/test/parallel/test-http2-reset-flood.js @@ -13,7 +13,7 @@ const { Worker, parentPort } = require('worker_threads'); // the two event loops intermixing, as we are writing in a busy loop here. if (process.env.HAS_STARTED_WORKER) { - const server = http2.createServer(); + const server = http2.createServer({ maxSessionInvalidFrames: 100 }); server.on('stream', (stream) => { stream.respond({ 'content-type': 'text/plain', @@ -59,19 +59,22 @@ const worker = new Worker(__filename).on('message', common.mustCall((port) => { }); let gotError = false; + let streamId = 1; function writeRequests() { - for (let i = 1; !gotError; i += 2) { + for (let i = 1; i < 10 && !gotError; i++) { h2header[3] = 1; // HEADERS h2header[4] = 0x5; // END_HEADERS|END_STREAM h2header.writeIntBE(1, 0, 3); // Length: 1 - h2header.writeIntBE(i, 5, 4); // Stream ID + h2header.writeIntBE(streamId, 5, 4); // Stream ID + streamId += 2; // 0x88 = :status: 200 if (!conn.write(Buffer.concat([h2header, Buffer.from([0x88])]))) { - process.nextTick(writeRequests); break; } } + if (!gotError) + setImmediate(writeRequests); } conn.once('error', common.mustCall(() => {