node: invoke `beforeExit` again if loop was active

When `setImmediate(cb)` is called in `beforeExit` event handler the
consequent `uv_run(..., UV_RUN_NOWAIT)` may return `0`, even if there
was some active handles at start.

Fixes simple/test-beforeexit-event.js.
pull/5010/head
Fedor Indutny 2014-02-28 17:25:28 +04:00
parent 3b88dc6f19
commit 5596f936d8
1 changed files with 6 additions and 1 deletions

View File

@ -3536,7 +3536,12 @@ int Start(int argc, char** argv) {
more = uv_run(env->event_loop(), UV_RUN_ONCE);
if (more == false) {
EmitBeforeExit(env);
more = uv_run(env->event_loop(), UV_RUN_NOWAIT);
// 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;
}
} while (more == true);
code = EmitExit(env);