Skip to content

fix(NODE-4845): allocate sessions lazily in cursors #4575

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

Merged
merged 5 commits into from
Jul 5, 2025

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Jul 2, 2025

Description

What is changing?

When no explicit session is provided to a cursor, we now instantiate an implicit session when initializing the cursor, instead of in the cursor's constructor.

Release Highlight

Cursors lazily instantiate sessions

In previous versions, sessions were eagerly allocated whenever a cursor was created, regardless of whether or not a cursor was actually iterated (and the session was actually needed). Some driver APIs (FindCursor.count(), AggregationCursor.explain() and FindCursor.explain()) don't actually iterate the cursor they are executed on. This can lead to client sessions being created and never being cleaned up.

With this update, sessions are not allocated until the cursor is iterated.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@baileympearson baileympearson marked this pull request as ready for review July 2, 2025 18:46
@baileympearson baileympearson requested review from a team as code owners July 2, 2025 18:46
@durran durran self-assigned this Jul 3, 2025
@durran durran added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jul 3, 2025
durran
durran previously approved these changes Jul 3, 2025
@durran durran self-requested a review July 3, 2025 21:43
@durran durran dismissed their stale review July 3, 2025 21:46

Need to re-review.

@baileympearson baileympearson requested a review from dariakp July 3, 2025 21:56
@durran durran merged commit 5761703 into mongodb:main Jul 5, 2025
27 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants