-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 4.9.0
-
Component/s: None
What problem are you facing?
When using an async iterator, like
const cursor = col.find() for await (const doc of query) { console.log(doc) break }
breaking the iterator before the end causes a memory leak. The 'sessions' used on the find are not closed/cleaned up
Printing activeSessions's size from client.s.activeSessions reveals that, when breaking in the middle of an async iterator (before the end), the number of sessions increases indefinitely, which does NOT happen if you consume the iterator thought the end (the number stays consistent)
What driver and relevant dependency versions are you using?
mongodb driver for nodejs, latest version (4.9.0)
It seems that the bug was introduced on [#3286|https://github.com/mongodb/node-mongodb-native/pull/3286,] it was the last PR that changed the src/mongo_client.ts and introduced the activeSessions Set
I've tested it with a version before this commit (4.5.0), that uses the old sessions Set and the leak seems to not happen
Steps to reproduce?
I've made a repository to reproduce this bug: https://github.com/GCastilho/mongodb-cursor-memory-leak
Just clone it, and run 'npm start'. The used data as well as the 'activeSessions' will be printed periodically for one minute
- depends on
-
NODE-4599 Investigate NODE-4598 - memory leak when breaking in the middle of a cursor's async iterator
- Closed