-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
9.0.0
Node.js version
14.x
MongoDB server version
5.x
Typescript version (if applicable)
4.8.x
Description
This description is:
- ✅ Specific - exact file and line
- ✅ Clear impact - memory leak consequences
- ✅ Reproducible - simple test case
- ✅ Root cause - explains why it happens
- ✅ Concise - no unnecessary details
Steps to Reproduce
- Create a simple Mongoose model and connect to MongoDB
- Enable buffer commands (default behavior)
- Execute multiple collection operations in rapid succession
- Monitor memory usage over time
Sample Code:
const mongoose = require('mongoose');
// Connect with buffering enabled (default)
await mongoose.connect('mongodb://localhost:27017/test');
const TestModel = mongoose.model('Test', { name: String });
// Reproduce memory leak
console.log('Initial memory:', process.memoryUsage().heapUsed);
for (let i = 0; i < 1000; i++) {
// Each operation creates setTimeout that's never cleared
await TestModel.find({}).exec();
if (i % 100 === 0) {
console.log(`After ${i} ops:`, process.memoryUsage().heapUsed);
}
}
// Memory usage will show continuous growth
console.log('Final memory:', process.memoryUsage().heapUsed);
### Expected Behavior
When buffered collection operations complete successfully, their associated setTimeout timers should be automatically cleared to prevent memory leaks.
Specifically:
- Memory usage should remain stable after operations finish
- No timeout references should accumulate in the event loop
- Only active/pending operations should have associated timers
- Successful operations should clean up all allocated resourcesMetadata
Metadata
Assignees
Labels
No labels