Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 3fe90cf

Browse files
bnoordhuiskevinsawicki
authored andcommitted
lib: fix event race condition with -e
Commit c5b07d4 ("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. PR-URL: nodejs/node#11958 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent a666359 commit 3fe90cf

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/internal/bootstrap_node.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,9 @@
384384
'return require("vm").runInThisContext(' +
385385
`${JSON.stringify(body)}, { filename: ` +
386386
`${JSON.stringify(name)}, displayErrors: true });\n`;
387-
// Defer evaluation for a tick. This is a workaround for deferred
388-
// events not firing when evaluating scripts from the command line,
389-
// see https://github.com/nodejs/node/issues/1600.
390-
setImmediate(function() {
391-
const result = module._compile(script, `${name}-wrapper`);
392-
if (process._print_eval) console.log(result);
393-
});
387+
const result = module._compile(script, `${name}-wrapper`);
388+
if (process._print_eval) console.log(result);
389+
process._tickCallback();
394390
}
395391

396392
// Load preload modules

0 commit comments

Comments
 (0)