summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2017-03-21 11:30:59 +0100
committerJames M Snell <jasnell@gmail.com>2017-03-24 09:19:09 -0700
commit9ff7ed23cd822dc810ddd99d63d4e2ca68635474 (patch)
treeb48ac0c73921cbbe0b69dcea2c2e06b0a859eaa6 /lib
parent30f1e8ea041c97370534b9d26eef8f25da18a75c (diff)
downloadandroid-node-v8-9ff7ed23cd822dc810ddd99d63d4e2ca68635474.tar.gz
android-node-v8-9ff7ed23cd822dc810ddd99d63d4e2ca68635474.tar.bz2
android-node-v8-9ff7ed23cd822dc810ddd99d63d4e2ca68635474.zip
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: https://github.com/nodejs/node/pull/11958 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/bootstrap_node.js10
1 files changed, 3 insertions, 7 deletions
diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js
index f29f7a647a..51b7f928cb 100644
--- a/lib/internal/bootstrap_node.js
+++ b/lib/internal/bootstrap_node.js
@@ -400,13 +400,9 @@
'return require("vm").runInThisContext(' +
`${JSON.stringify(body)}, { filename: ` +
`${JSON.stringify(name)}, displayErrors: true });\n`;
- // Defer evaluation for a tick. This is a workaround for deferred
- // events not firing when evaluating scripts from the command line,
- // see https://github.com/nodejs/node/issues/1600.
- setImmediate(function() {
- const result = module._compile(script, `${name}-wrapper`);
- if (process._print_eval) console.log(result);
- });
+ const result = module._compile(script, `${name}-wrapper`);
+ if (process._print_eval) console.log(result);
+ process._tickCallback();
}
// Load preload modules