作为我的应用程序的一部分,我具有以下代码行:

process.nextTick(function() {
  // pre-populate cache with all users
  console.log('scanning users table in order to pre-populate cache');
  tables.users.scan(function(err, users) {
    if (err) {
      console.error('unable to scan users database in order to pre-populate cache');
      return;
    }

    console.log('found %d users in database', users.length);
  });
});

在ubuntu中运行该应用程序给了我
(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

在OSX上运行的程序运行良好,完全没有警告。

两者都运行相同的 Node 版本v0.10.24

删除此代码块即可解决该问题。我试图弄清楚这里发生了什么。

尝试使用--trace-deprecation标志运行 Node 显示
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
    at maxTickWarn (node.js:377:17)
    at process.nextTick (node.js:480:9)
    at onwrite (_stream_writable.js:260:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:651:5)
    at doWrite (_stream_writable.js:221:10)
    at writeOrBuffer (_stream_writable.js:211:5)
    at WriteStream.Writable.write (_stream_writable.js:180:11)
    at WriteStream.Socket.write (net.js:613:40)
    at Console.warn (console.js:61:16)
    at Console.trace (console.js:95:8)
    at maxTickWarn (node.js:377:17)

使用--throw-deprecation运行可以
Error: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
    at maxTickWarn (node.js:375:15)
    at process.nextTick (node.js:480:9)
    at Cursor.each (/var/www/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:184:13)
    at /var/www/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:191:16
    at Cursor.nextObject (/var/www/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:540:5)
    at /var/www/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:187:12
    at process._tickCallback (node.js:415:13)

任何帮助,不胜感激。

10倍

最佳答案

事实证明,问题出在我在我的应用程序mongojs中使用的模块之一。在模块的更高版本中解决了该问题,我只需要更新package.json即可。

Jamis Charles关于使用node --throw-deprecation app.js(或--trace-deprecation)运行我的应用程序的评论向我显示了导致我进入罪魁祸首模块的错误的堆栈跟踪。

我仍然不确定为什么问题会在Ubuntu上而不是在我的MBA上出现...

关于javascript - 递归process.nextTick警告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20792341/

10-12 15:43