Node.js - diagnose "(node) warning: recursive process.nextTick detected."

In my application, there is a situation where the operation takes a very long time, and then several hundred copies of the following message are issued:

(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.

And then the application crashes:

RangeError: Maximum call stack size exceeded

No stack trace.

How can I diagnose such errors? For example, I would like to know which function call preceded RangeError.

To replicate the error, run node foo.jsin the file foo.jswith the following contents:

var foo = function () {
    process.nextTick(foo);
};
foo();

I am not interested in the specific cause of this problem in my application, since I know how to diagnose this type of problem in node.

Node version v0.10.39.

+4
source share
1 answer

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);
};
0

Source: https://habr.com/ru/post/1598980/


All Articles