Skip to content

Commit 875e4a0

Browse files
committed
core: Remove the nextTick for running the main file
Not necessary, since we can handle the error properly on the first tick now, even if there are event listeners, etc. Additionally, this removes the unnecessary "_needTickCallback" from startup, since Module.loadMain() will kick off a nextTick callback right after it runs the main module. Fix nodejs#4856
1 parent 95862b2 commit 875e4a0

File tree

8 files changed

+43
-22
lines changed

8 files changed

+43
-22
lines changed

lib/module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ Module._extensions['.node'] = process.dlopen;
495495
Module.runMain = function() {
496496
// Load the main module--the command line argument.
497497
Module._load(process.argv[1], null, true);
498+
// Handle any nextTicks added in the first tick of the program
499+
process._tickCallback();
498500
};
499501

500502
Module._initPaths = function() {

src/node.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@
114114
setTimeout(Module.runMain, debugTimeout);
115115

116116
} else {
117-
// REMOVEME: nextTick should not be necessary. This hack to get
118-
// test/simple/test-exception-handler2.js working.
119117
// Main entry point into most programs:
120-
process.nextTick(Module.runMain);
118+
Module.runMain();
121119
}
122120

123121
} else {
@@ -156,8 +154,6 @@
156154
});
157155
}
158156
}
159-
160-
process._needTickCallback();
161157
}
162158

163159
startup.globalVariables = function() {

test/message/error_exit.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ AssertionError: 1 == 2
99
at Object.Module._extensions..js (module.js:*:*)
1010
at Module.load (module.js:*:*)
1111
at Function.Module._load (module.js:*:*)
12-
at Module.runMain (module.js:*:*)
13-
at _tickCallback (node.js:*:*)
14-
at process._tickFromSpinner (node.js:*:*)
12+
at Function.Module.runMain (module.js:*:*)
13+
at startup (node.js:*:*)
14+
at node.js:*:*

test/message/max_tick_depth.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ tick 15
77
tick 14
88
tick 13
99
tick 12
10-
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
1110
tick 11
11+
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
1212
tick 10
1313
tick 9
1414
tick 8
@@ -18,6 +18,6 @@ tick 5
1818
tick 4
1919
tick 3
2020
tick 2
21-
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
2221
tick 1
22+
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
2323
tick 0

test/message/max_tick_depth_trace.out

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ tick 15
77
tick 14
88
tick 13
99
tick 12
10+
tick 11
1011
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
1112
at maxTickWarn (node.js:*:*)
12-
at process.nextTick (node.js:*:*
13+
at process.nextTick (node.js:*:*)
1314
at f (*test*message*max_tick_depth_trace.js:*:*)
14-
at _tickCallback (node.js:*:*)
15-
at process._tickFromSpinner (node.js:*:*)
16-
tick 11
15+
at process._tickCallback (node.js:*:*)
16+
at Function.Module.runMain (module.js:*:*)
17+
at startup (node.js:*:*)
18+
at node.js:*:*
1719
tick 10
1820
tick 9
1921
tick 8
@@ -23,11 +25,11 @@ tick 5
2325
tick 4
2426
tick 3
2527
tick 2
28+
tick 1
2629
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
2730
at maxTickWarn (node.js:*:*)
28-
at process.nextTick (node.js:*:*
31+
at process.nextTick (node.js:*:*)
2932
at f (*test*message*max_tick_depth_trace.js:*:*)
3033
at _tickCallback (node.js:*:*)
3134
at process._tickFromSpinner (node.js:*:*)
32-
tick 1
3335
tick 0

test/message/nexttick_throw.out

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
12
*test*message*nexttick_throw.js:*
23
undefined_reference_error_maker;
34
^
45
ReferenceError: undefined_reference_error_maker is not defined
56
at *test*message*nexttick_throw.js:*:*
6-
at _tickCallback (node.js:*:*)
7-
at process._tickFromSpinner (node.js:*:*)
7+
at process._tickCallback (node.js:*:*)
8+
at Function.Module.runMain (module.js:*:*)
9+
at startup (node.js:*:*)
10+
at node.js:*:*

test/message/undefined_reference_in_new_context.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ReferenceError: foo is not defined
99
at Module._compile (module.js:*)
1010
at *..js (module.js:*)
1111
at Module.load (module.js:*)
12-
at *._load (module.js:*)
13-
at Module.runMain (module.js:*)
14-
at _tickCallback (node.js:*)
15-
at *._tickFromSpinner (node.js:*)
12+
at Function.Module._load (module.js:*:*)
13+
at Function.Module.runMain (module.js:*:*)
14+
at startup (node.js:*:*)
15+
at node.js:*:*

test/simple/test-domain.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ d.on('error', function(er) {
110110
assert.ok(!er.domainBound);
111111
break;
112112

113+
case 'nextTick execution loop':
114+
assert.equal(er.domain, d);
115+
assert.ok(!er.domainEmitter);
116+
assert.ok(!er.domainBound);
117+
break;
118+
113119
default:
114120
console.error('unexpected error, throwing %j', er.message, er);
115121
throw er;
@@ -127,6 +133,18 @@ process.on('exit', function() {
127133
});
128134

129135

136+
137+
// revert to using the domain when a callback is passed to nextTick in
138+
// the middle of a tickCallback loop
139+
d.run(function() {
140+
process.nextTick(function() {
141+
throw new Error('nextTick execution loop');
142+
});
143+
});
144+
expectCaught++;
145+
146+
147+
130148
// catch thrown errors no matter how many times we enter the event loop
131149
// this only uses implicit binding, except for the first function
132150
// passed to d.run(). The rest are implicitly bound by virtue of being

0 commit comments

Comments
 (0)