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

Connection pool wait queue processing is too greedy

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.6.2
    • None
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: