递归的 process.nextTick 警告

5
作为我的应用程序的一部分,我有以下代码行:
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上运行良好,没有任何警告。

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

删除这个代码块就解决了问题。我试图弄清楚这里发生了什么。

尝试使用--trace-deprecation标志运行节点会显示

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)

任何帮助都非常感激。
10x

4
这可能有助于故障排除:https://groups.google.com/forum/#!topic/nodejs/9_uM04IDNWg - Jamis Charles
1个回答

4
原来问题出在我应用程序中使用的一个模块mongojs上。问题已经在该模块的后续版本中得到解决,我只需要更新我的package.json即可。
Jamis Charles提到运行我的应用程序时使用node --throw-deprecation app.js(或--trace-deprecation)可以显示导致错误的堆栈跟踪,从而找到问题所在的模块。
我仍然不确定为什么问题会在Ubuntu上出现而不是在我的MBA上...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接