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

fix: memory-leak in .transaction() #11259

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ declare module 'mongoose' {
* _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
* in a transaction. Mongoose will commit the transaction if the
* async function executes successfully and attempt to retry if
* there was a retriable error.
* there was a retryable error.
*/
transaction(fn: (session: mongodb.ClientSession) => Promise<any>): Promise<any>;

Expand Down
4 changes: 4 additions & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ Connection.prototype.transaction = function transaction(fn, options) {
}
delete session[sessionNewDocuments];
throw err;
})
.finally(() => {
session.endSession()
.catch(() => {});
});
});
};
Expand Down