Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursive process.nextTick warning

As part of my app, I have the following lines of code:

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

running the app in ubuntu gives me

(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

running on OSX is working good no warnings at all.

Both run the same node version v0.10.24.

Removing this block of code solves the problem. I am trying to figure out what's going on here.

Trying to run node with --trace-deprecation flag shows

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)

running with --throw-deprecation gives

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)

Any help much appreciated.

10x

like image 510
Michael Avatar asked Oct 02 '22 01:10

Michael


1 Answers

It turns out the problem was in one of the modules I used in my app - mongojs. The problem was solved in a later version of the module, I just needed to update my package.json.

Jamis Charles comment about running my app with node --throw-deprecation app.js (or --trace-deprecation) showed me the stack trace of the error that led me to the culprit module.

I'm still not sure why the problem showed in Ubuntu and not on my MBA...

like image 191
Michael Avatar answered Oct 12 '22 23:10

Michael