[英]Node.js - Diagnose “(node) warning: Recursive process.nextTick detected.”
我的應用程序有一種情況,即操作需要很長時間才能完成,然后打印以下消息的幾百個實例:
(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
之前。
要復制錯誤, node foo.js
在文件foo.js
上運行node foo.js
,其中包含以下內容:
var foo = function () {
process.nextTick(foo);
};
foo();
我對應用程序中此問題的特定原因並不感興趣,因為我知道如何在節點中診斷此類問題。
節點版本為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);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.