From f157bc6de863535712993040e64fd253e49f9af2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 25 Jan 2020 02:07:12 +0100 Subject: [PATCH 1/2] test: make test-http2-buffersize more correct Previously, this code could have closed the server before the connection was actually received by the server, as the `'close'` event on the client side can be emitted before the connection is established. The following commit exacerbates this problem, so fix the test first. --- test/parallel/test-http2-buffersize.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-http2-buffersize.js b/test/parallel/test-http2-buffersize.js index be56d8ce3d9344..f18cc4c1ec4e18 100644 --- a/test/parallel/test-http2-buffersize.js +++ b/test/parallel/test-http2-buffersize.js @@ -15,29 +15,32 @@ const Countdown = require('../common/countdown'); const BUFFER_SIZE = 30; const server = createServer(); + let client; + const countdown = new Countdown(SOCKETS, () => { + client.close(); + server.close(); + }); + // Other `bufferSize` tests for net module and tls module // don't assert `bufferSize` of server-side sockets. server.on('stream', mustCall((stream) => { stream.on('data', mustCall()); stream.on('end', mustCall()); + + stream.on('close', mustCall(() => { + countdown.dec(); + })); }, SOCKETS)); server.listen(0, mustCall(() => { const authority = `http://localhost:${server.address().port}`; - const client = connect(authority); - const countdown = new Countdown(SOCKETS, () => { - client.close(); - server.close(); - }); + client = connect(authority); client.once('connect', mustCall()); for (let j = 0; j < SOCKETS; j += 1) { const stream = client.request({ ':method': 'POST' }); stream.on('data', () => {}); - stream.on('close', mustCall(() => { - countdown.dec(); - })); for (let i = 0; i < TIMES; i += 1) { stream.write(Buffer.allocUnsafe(BUFFER_SIZE), mustCall()); From f5a5807d8a734da093679d184b119d8138484dd5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 25 Jan 2020 02:02:57 +0100 Subject: [PATCH 2/2] src: simplify native immediate queue running Make `SetImmediate()` behave more like `process.nextTick()` (which matches how we use it) by also running tasks that have been added during previous `SetImmediate()` calls. --- src/env.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/env.cc b/src/env.cc index 19c29c2fcab950..36b41c5fac56c4 100644 --- a/src/env.cc +++ b/src/env.cc @@ -685,13 +685,11 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) { native_immediates_.ConcatMove(std::move(native_immediates_threadsafe_)); } - NativeImmediateQueue queue; - queue.ConcatMove(std::move(native_immediates_)); - auto drain_list = [&]() { TryCatchScope try_catch(this); DebugSealHandleScope seal_handle_scope(isolate()); - while (std::unique_ptr head = queue.Shift()) { + while (std::unique_ptr head = + native_immediates_.Shift()) { if (head->is_refed()) ref_count++; @@ -709,7 +707,7 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) { } return false; }; - while (queue.size() > 0 && drain_list()) {} + while (drain_list()) {} immediate_info()->ref_count_dec(ref_count);