我的应用程序有一个操作需要很长时间才能完成的情况,然后会打印数百个以下消息实例:
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
然后应用程序崩溃:
RangeError: Maximum call stack size exceeded
没有堆栈跟踪。
如何诊断此类错误?例如,我想知道 RangeError
之前调用了哪个函数。
要重现错误,请在文件 foo.js
上运行 node foo.js
并包含以下内容:
var foo = function () {
process.nextTick(foo);
};
foo();
我对我的应用程序中此问题的具体原因不太感兴趣,因为我知道如何诊断 Node 中的此类问题。
Node 版本是 v0.10.39
。
最佳答案
您可以替换 process.nextTick
来打印一些有用的信息——类似于:
var _nextTick = process.nextTick;
var alreadyLogged = new Set();
process.nextTick = function nextTick(f) {
if (!alreadyLogged.has(f)) {
alreadyLogged.add(f);
process.nextTick = _nextTick;
console.log(f);
process.nextTick = nextTick;
}
return _nextTick.apply(this, arguments);
};
关于javascript - Node.js - 诊断 "(node) warning: Recursive process.nextTick detected.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31551132/