Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.find().cursor().destroy() does not close the underlying mongodb cursor #14966

Closed
2 tasks done
SleepWalker opened this issue Oct 16, 2024 · 1 comment
Closed
2 tasks done
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. performance
Milestone

Comments

@SleepWalker
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the performance issue has not already been reported

Last performant version

Slowed down in version

8.1.1

Node.js version

16.20.2

🦥 Performance issue

When you use streaming API of QueryCursor and you need to destory stream for some reason (e.g. the upstream was destoryed too) it won't close the cursor and the cursor and session will hang in memory (activeSessions)

Steps to Reproduce

const mongoose = require('mongoose');
const Model = require('./Model');

const stream = Model.find().cursor();

console.log(stream.cursor.closed);

stream.destroy();

console.log(stream.destroyed);
console.log(stream.cursor.closed);
console.log([...mongoose.connection.client.s.activeSessions.values()])

Expected Behavior

It looks to me that the correct behavior should be — to automatically call cursor.close() when the stream is destroyed

@SleepWalker SleepWalker changed the title Model.find().cursor().destroy() does not closes the underlying mongodb cursor Model.find().cursor().destroy() does not close the underlying mongodb cursor Oct 16, 2024
@vkarpov15 vkarpov15 added this to the 8.7.3 milestone Oct 20, 2024
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Oct 20, 2024
vkarpov15 added a commit that referenced this issue Oct 23, 2024
@IslandRhythms
Copy link
Collaborator

IslandRhythms commented Oct 24, 2024

Given the PRs I'll mark this as a confirmed bug

@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Oct 24, 2024
vkarpov15 added a commit that referenced this issue Oct 25, 2024
fix(cursor): close underlying query cursor when calling destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. performance
Projects
None yet
Development

No branches or pull requests

3 participants