Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Cursor.toArray() fails for large number of records #39

Open
yangchristian opened this issue Oct 19, 2015 · 1 comment
Open

Cursor.toArray() fails for large number of records #39

yangchristian opened this issue Oct 19, 2015 · 1 comment

Comments

@yangchristian
Copy link

For a large number of records (600 to be exact, not sure why that is the magic number), toArray() fails and throws a Recursive process.nextTick detected error for each record (full stack trace at bottom).

We were able to create a minimal repro by adding a test similar to the toArray test, just with more records (also available in our fork branch):

    it('should be able to handle lots of documents', async function () {
      const docsToInsert = [], numDocs = 600;
      for (let i = 0; i < numDocs; i++) {
        docsToInsert[i] = {
          i,
          name: `Pokemon ID #${i}`
        };
      }
      await collection.insert(docsToInsert);

      let result = await collection.find().toArray();

      expect(result).to.be.an.instanceof(Array);
      expect(result.length).to.equal(numDocs);
    });

I suspect this has to do with the async while loop, however, I am unable to get the error to repro with a minimal Babel REPL, even with a high result count.

Here is the stack trace for each loop iteration:

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:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Console.warn (console.js:62:16)
    at Console.trace (console.js:122:8)
    at maxTickWarn (node.js:410:17)
    at process._nextTick [as _currentTickHandler] (node.js:513:9)
    at process.nextTick (node.js:364:15)
    at onwrite (_stream_writable.js:266:15)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at WriteStream.Socket._write (net.js:654:5)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at WriteStream.Writable.write (_stream_writable.js:183:11)
    at WriteStream.Socket.write (net.js:616:40)
    at Object.exports.cursor.deleteLine (C:\Users\C\AppData\Roaming\nvm\v0.10.38\node_modules\mocha\lib\reporters\base.js:137:30)
    at Object.exports.cursor.CR (C:\Users\C\AppData\Roaming\nvm\v0.10.38\node_modules\mocha\lib\reporters\base.js:146:22)
    at Runner.<anonymous> (C:\Users\C\AppData\Roaming\nvm\v0.10.38\node_modules\mocha\lib\reporters\spec.js:67:14)
    at Runner.emit (events.js:117:20)
    at C:\Users\C\AppData\Roaming\nvm\v0.10.38\node_modules\mocha\lib\runner.js:547:14
    at done (C:\Users\C\AppData\Roaming\nvm\v0.10.38\node_modules\mocha\lib\runnable.js:247:5)
    at C:\Users\C\AppData\Roaming\nvm\v0.10.38\node_modules\mocha\lib\runnable.js:291:11
    at run (C:\htdocs\promised-mongo\node_modules\babel\node_modules\babel-core\node_modules\core-js\modules\es6.promise.js:89:39)
    at C:\htdocs\promised-mongo\node_modules\babel\node_modules\babel-core\node_modules\core-js\modules\es6.promise.js:100:28
    at flush (C:\htdocs\promised-mongo\node_modules\babel\node_modules\babel-core\node_modules\core-js\modules\$.microtask.js:17:13)
    at process._tickCallback (node.js:448:13)
@yangchristian
Copy link
Author

(also note this used to work in v0.11, which is how we found out about the issue in the first place)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant