Skip to content

Commit 21c741f

Browse files
committed
Print warning when maxTickDepth is reached
1 parent 953b049 commit 21c741f

5 files changed

Lines changed: 129 additions & 1 deletion

File tree

src/node.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,18 @@
280280
}
281281
}
282282

283-
process._tickCallback = function(fromSpinner) {
283+
function maxTickWarn() {
284+
// XXX Remove all this maxTickDepth stuff in 0.11
285+
var msg = '(node) warning: Recursive process.nextTick detected. ' +
286+
'This will break in the next version of node. ' +
287+
'Please use setImmediate for recursive deferral.';
288+
if (process.traceDeprecation)
289+
console.trace(msg);
290+
else
291+
console.error(msg);
292+
}
284293

294+
process._tickCallback = function(fromSpinner) {
285295
// if you add a nextTick in a domain's error handler, then
286296
// it's possible to cycle indefinitely. Normally, the tickDone
287297
// in the finally{} block below will prevent this, however if
@@ -348,6 +358,9 @@
348358
// it won't get fired anyway.
349359
if (process._exiting) return;
350360

361+
if (tickDepth >= process.maxTickDepth)
362+
maxTickWarn();
363+
351364
var tock = { callback: callback };
352365
if (process.domain) tock.domain = process.domain;
353366
nextTickQueue.push(tock);

test/message/max_tick_depth.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common');
23+
24+
process.maxTickDepth = 10;
25+
var i = 20;
26+
process.nextTick(function f() {
27+
console.error('tick %d', i);
28+
if (i-- > 0)
29+
process.nextTick(f);
30+
});

test/message/max_tick_depth.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
tick 20
2+
tick 19
3+
tick 18
4+
tick 17
5+
tick 16
6+
tick 15
7+
tick 14
8+
tick 13
9+
tick 12
10+
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
11+
tick 11
12+
tick 10
13+
tick 9
14+
tick 8
15+
tick 7
16+
tick 6
17+
tick 5
18+
tick 4
19+
tick 3
20+
tick 2
21+
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
22+
tick 1
23+
tick 0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common');
23+
24+
process.maxTickDepth = 10;
25+
process.traceDeprecation = true;
26+
var i = 20;
27+
process.nextTick(function f() {
28+
console.error('tick %d', i);
29+
if (i-- > 0)
30+
process.nextTick(f);
31+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tick 20
2+
tick 19
3+
tick 18
4+
tick 17
5+
tick 16
6+
tick 15
7+
tick 14
8+
tick 13
9+
tick 12
10+
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
11+
at maxTickWarn (node.js:289:17)
12+
at process.nextTick (node.js:362:9)
13+
at f (*test*message*max_tick_depth_trace.js:30:13)
14+
at process._tickCallback (node.js:335:13)
15+
tick 11
16+
tick 10
17+
tick 9
18+
tick 8
19+
tick 7
20+
tick 6
21+
tick 5
22+
tick 4
23+
tick 3
24+
tick 2
25+
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
26+
at maxTickWarn (node.js:289:17)
27+
at process.nextTick (node.js:362:9)
28+
at f (*test*message*max_tick_depth_trace.js:30:13)
29+
at process._tickCallback (node.js:335:13)
30+
tick 1
31+
tick 0

0 commit comments

Comments
 (0)