Commit 1a7d633
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: #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>1 parent 4cb4803 commit 1a7d633Copy full SHA for 1a7d633
File tree
Expand file treeCollapse file tree
4 files changed
+72
-47
lines changedOpen diff view settings
Filter options
- lib/internal
- test
- message
- parallel
Expand file treeCollapse file tree
4 files changed
+72
-47
lines changedOpen diff view settings
Collapse file
lib/internal/bootstrap_node.js
Copy file name to clipboardExpand all lines: lib/internal/bootstrap_node.js+3-7Lines changed: 3 additions & 7 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
351 | 351 | |
352 | 352 | |
353 | 353 | |
354 | | - |
355 | | - |
356 | | - |
357 | | - |
358 | | - |
359 | | - |
360 | | - |
| 354 | + |
| 355 | + |
| 356 | + |
361 | 357 | |
362 | 358 | |
363 | 359 | |
|
Collapse file
test/message/eval_messages.out
Copy file name to clipboardExpand all lines: test/message/eval_messages.out+29-24Lines changed: 29 additions & 24 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3 | 3 | |
4 | 4 | |
5 | 5 | |
6 | | - |
7 | | - |
| 6 | + |
| 7 | + |
8 | 8 | |
9 | 9 | |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
14 | 15 | |
15 | 16 | |
16 | 17 | |
| ||
19 | 20 | |
20 | 21 | |
21 | 22 | |
22 | | - |
23 | | - |
| 23 | + |
| 24 | + |
24 | 25 | |
25 | 26 | |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
30 | 33 | |
31 | 34 | |
32 | 35 | |
33 | 36 | |
34 | 37 | |
35 | 38 | |
36 | | - |
37 | | - |
| 39 | + |
| 40 | + |
38 | 41 | |
39 | 42 | |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
44 | 48 | |
45 | 49 | |
46 | 50 | |
47 | 51 | |
48 | 52 | |
49 | 53 | |
50 | 54 | |
51 | | - |
52 | | - |
| 55 | + |
| 56 | + |
53 | 57 | |
54 | 58 | |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
59 | 64 | |
60 | 65 | |
61 | 66 | |
|
Collapse file
test/message/stdin_messages.out
Copy file name to clipboardExpand all lines: test/message/stdin_messages.out+21-16Lines changed: 21 additions & 16 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
7 | 7 | |
8 | 8 | |
9 | 9 | |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
14 | 16 | |
15 | 17 | |
16 | 18 | |
| ||
23 | 25 | |
24 | 26 | |
25 | 27 | |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
30 | 33 | |
31 | 34 | |
32 | 35 | |
| ||
37 | 40 | |
38 | 41 | |
39 | 42 | |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
44 | 48 | |
45 | 49 | |
46 | 50 | |
| ||
52 | 56 | |
53 | 57 | |
54 | 58 | |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
59 | 64 | |
60 | 65 | |
61 | 66 | |
|
Collapse file
test/parallel/test-cli-eval.js
Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js+19Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
144 | 144 | |
145 | 145 | |
146 | 146 | |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
0 commit comments