递归process.nextTick警告

时间:2013-12-26 22:56:11

标签: javascript node.js

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

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)

任何帮助都非常感激。

10倍

1 个答案:

答案 0 :(得分:4)

事实证明问题出在我在我的应用中使用的模块之一 - mongojs。该问题已在该模块的更高版本中得到解决,我只需要更新我的package.json

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

我还不确定为什么问题出现在Ubuntu而不是我的MBA ......