Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2803

Connection pool wait queue processing is too greedy

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Running the following snippet will result in a Maximum call stack exceeded error:

      const { MongoClient } = require('mongodb');
      async function main(pid) {
        const client = new MongoClient('mongodb://localhost:27017/', { useNewUrlParser: true, useUnifiedTopology: true });
        await client.connect()
      
        const collection = client.db().collection('test');
        await collection.insertOne({ a: 42 });
        for (let counter = 0; counter < 100000; counter++) {
          collection.insertOne({ a: 42 }, _ => {});
        }
      
        await client.close();
      }
      
      main().catch(console.error);
      

      The logic for processing the wait queue in the ConnectionPool attempts to process wait queue members in a very tight, greedy loop. We must use process.nextTick in order to let the runtime process background tasks, as well as allowing the garbage collector to run.

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            matt.broadstone@mongodb.com Matt Broadstone
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: