Browse Source

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.
v0.11.12-release
Fedor Indutny 11 years ago
parent
commit
5596f936d8
  1. 7
      src/node.cc

7
src/node.cc

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

Loading…
Cancel
Save