Repository navigation
process: flaky behavior of 'exit' event handler #12322
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.processIssues and PRs related to the process subsystem.Issues and PRs related to the process subsystem.
on Apr 11, 2017 What about a timeout of 1, is that flaky?
@sam-github For me, yes, it is.
I think a timeout of 0 is the same as 1 due to this code.
fwiw, I prefer (2), since (1) might make people think that there would be no flakiness, even if the timeout were lowered.
Reacted by Vse Mozhe ButyI’m not sure, but isn’t it a bug that that code actually runs?
Smells like a bug to me.
@sam-github @addaleax Could we check this for various OS?
I've checked for various Node.js versions in Windows 7 x64:
Node.js 4.8.2 x64 (v8 4.5.103.46)
consistently not runNode.js 6.10.2 x64 (v8 5.1.281.98)
consistently not runNode.js 7.8.0 x64 (v8 5.5.372.43)
flakyNode.js 8.0.0-nightly201703249ff7ed23cd x64 (v8 5.6.326.57)
flakyNode.js 8.0.0-nightly20170404394b6ac5cb x64 (v8 5.7.492.69)
flakyNode.js 8.0.0-pre x64 (v8 5.8.202)
flakyNode.js 8.0.0-pre x64 (v8 5.9.0 candidate turbo on)
flakyNode.js 8.0.0-pre x64 (v8 5.9.0 candidate turbo off)
flakyI can confirm, the behaviour differs between Node 6 and Node 7 on x64 Linux, too.
Reacted by Dave Mackintosh- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Apr 11, 2017 Does this only happen if you let the process expire normally, or also if you call
process.exit()?If it does not happen withprocess.exit(), it is simply a race condition with thebeforeExithandler, I think:Lines 4383 to 4392 in affe0f2
if (more == false) { v8_platform.PumpMessageLoop(isolate); EmitBeforeExit(&env); // Emit `beforeExit` if the loop became alive either after emitting // event, or after running some callbacks. more = uv_loop_alive(env.event_loop()); if (uv_run(env.event_loop(), UV_RUN_NOWAIT) != 0) more = true; } - removedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Apr 11, 2017 ok I just double-checked and that doesn't make sense because your scheduling it in the exit handler... Smells like a bug but I'm not sure where
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Apr 11, 2017 - changed the title
[-]doc: flaky example for 'exit' event[/-][+]process: flaky behavior of 'exit' event handler[/+]on Apr 11, 2017 1 remaining item
- removeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Apr 11, 2017 It's caused by the
while (handle_cleanup_waiting_ != 0) uv_run(event_loop(), UV_RUN_ONCE)loop in the Environment destructor.aac79df merges CleanupHandles() into the destructor, before that commit it was only used in debug-agent.cc.
@bnoordhuis Thanks for explaining, makes sense. I would say this is a bug that we should fix by ensuring the “old” behaviour; do you agree? And if you do, would you prefer to do that yourself? I should be able to take care of it, too.
Maybe a test could be added to check old behavior.
Oh, yeah, definitely – we should have a test for that, no matter whether we change behaviour or not. One can turn your code into a non-flaky version like this:
process.on('exit', (code) => { setTimeout(() => { console.log('This will not run'); // crash or w/e }, 0); // busy loop to make sure the timeout always expires during this tick const a = process.hrtime(); while (process.hrtime(a)[1] < 5000); });
- added a commit that references this issue
on Apr 19, 2017 Fixed in 5ef6000.
- added a commit that references this issue
on May 2, 2017 - added a commit that references this issue
on Apr 1, 2018 - added a commit that references this issue
on Apr 2, 2018 - added a commit that references this issue
on Dec 4, 2018
process.mdstates:However, the behavior of the code is flaky:
If this flakiness is not a bug, what would be better?
1000or something and save the categorical 'the timeout will never occur'.