Skip to content

(WIP) lib: fix beforeExit not working with -e

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test, lib

Description of change

This is an attempted backport of https://github.com/nodejs/node/commit/c5b07d4ec6de2cb362b887499e44655eaeb26cba to v4.x

It involved manually recreating the entire commit, as bootstrap_node.js does not exist in v4.x and the stack traces for the tests are quite different.

Unfortunately when running the tests we are seeing a failure in test/parallel/test-debug-brk.js. The node process for that test is not exiting and it is leaving phantom processes running 👻

Please do not run this in CI until we have figured out what is going on with the phantom processes.

@bnoordhuis do you have any idea why this is happening?

/cc @nodejs/lts

Commit 93a44d52 ("src: fix deferred events not working with -e") defers evaluation of the script to the next tick.

A side effect of that change is that 'beforeExit' listeners run before the actual script. 'beforeExit' is emitted when the event loop is empty but process.nextTick() does not ref the event loop.

Fix that by using setImmediate(). Because it is implemented in terms of a uv_check_t handle, it interacts with the event loop properly.

Fixes: https://github.com/nodejs/node/issues/8534 PR-URL: https://github.com/nodejs/node/pull/8821 Reviewed-By: Colin Ihrig cjihrig@gmail.com

Merge request reports

Loading