Skip to content

lib: fix event race condition with -e

Rodrigo Muino Tomonari requested to merge github/fork/bnoordhuis/fix11948 into master

Commit c5b07d4e ("lib: fix beforeExit not working with -e") runs the to-be-evaluated code at a later time than before because it switches from process.nextTick() to setImmediate().

It affects -e 'process.on("message", ...)' because there is now a larger time gap between startup and attaching the event listener, increasing the chances of missing early messages. I'm reasonably sure process.nextTick() was also susceptible to that, only less pronounced.

Avoid the problem altogether by evaluating the code synchronously. Harmonizes the logic with Module.runMain() from lib/module.js which also calls process._tickCallback() afterwards.

Merge request reports

Loading