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(NODE-5587): recursive calls to next cause memory leak #3842

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Aug 23, 2023

Description

What is changing?

  • Modified the isDead condition (moved it to a getter)
    • If the cursorId is zero, if it has been closed or has been killed, it's "dead"
    • if kId is nullish, it has not been initialized yet, a not-even-started-yet cursor is not dead
    • (this[kId]?.isZero() ?? false) || this[kClosed] || this[kKilled];
Is there new documentation needed for these changes?

No

Release Highlight

Fix memory leak with ChangeStreams

In a previous release, 5.7.0, we refactored cursor internals from callbacks to async/await. In particular, the next function that powers cursors was written with callbacks and would recursively call itself depending on the cursor type. For ChangeStreams, this function would call itself if there were no new changes to return to the user. After converting that code to async/await each recursive call created a new promise that saved the current async context. This would slowly build up memory usage if no new changes came in to unwind the recursive calls.

The function is now implemented as a loop, memory leak be gone!

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

@nbbeeken nbbeeken force-pushed the NODE-5502-next-loop-5x branch from 6ce78d2 to 7c7c7f0 Compare August 25, 2023 18:21
@nbbeeken nbbeeken force-pushed the NODE-5502-next-loop-5x branch from 7c7c7f0 to 4199e48 Compare August 25, 2023 18:22
@nbbeeken nbbeeken changed the title fix(NODE-5502): recursive calls to next cause memory leak fix(NODE-5587): recursive calls to next cause memory leak Aug 25, 2023
@nbbeeken nbbeeken marked this pull request as ready for review August 25, 2023 19:52
@durran durran self-assigned this Aug 29, 2023
@durran durran added the Team Review Needs review from team label Aug 29, 2023
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same changes as 6.x.

@durran durran merged commit f60f1b5 into 5.x Aug 29, 2023
@durran durran deleted the NODE-5502-next-loop-5x branch August 29, 2023 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants