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

Concurrent calls to MongoClient.close() throw

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      What problem are you facing?

      When we have concurrent calls to MongoClient.close() we get an error:

       

      TypeError: Cannot read properties of undefined (reading 'close')
          at /Users/alec/git/work/reedsy/reedsy-editor/node_modules/mongodb/src/mongo_client.ts:530:16
          at new Promise (<anonymous>)
          at MongoClient.close (/Users/alec/git/work/reedsy/reedsy-editor/node_modules/mongodb/src/mongo_client.ts:529:11)
          at processTicksAndRejections (node:internal/process/task_queues:95:5) 

       

       

      What driver and relevant dependency versions are you using?

      Server: 4.4

      Driver: 5.3.0

      Steps to reproduce?

      Call client.close() in quick succession on the same client. Looking at the code, it looks like if you do this:

      1. The first call attempts to asynchronously close the session pool sessions
      2. While this is happening, the second call passes the topology null check (since this.topology hasn't yet been unset, and tries to also close session pool sessions
      3. Both calls then set const topology = this.topology but the second call will get undefined since the first call unset this.topology
      4. The second call now tries to call close() on an undefined topology and throws

            Assignee:
            Unassigned Unassigned
            Reporter:
            alec@reedys.com Alec Gibson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: