-
Type: Bug
-
Resolution: Unresolved
-
Priority: 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:
- The first call attempts to asynchronously close the session pool sessions
- 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
- Both calls then set const topology = this.topology but the second call will get undefined since the first call unset this.topology
- The second call now tries to call close() on an undefined topology and throws