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-5993): memory leak in the Connection class #4022

Merged
merged 5 commits into from Mar 7, 2024

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Mar 6, 2024

Description

What is changing?

  • Remove promise wrapping of signal
  • Make writing async based on whether or not write returns true
  • Remove signal
Is there new documentation needed for these changes?

What is the motivation for this change?

The Connection class stored a promise that would reject when the signal was aborted. This caused a leak that would create new promises unbounded. I've removed the promise wrapping opting for a simpler implementation that only makes writing async if there was buffering. If there was buffering we wait for the drain event and use try/finally to make sure we clean up event listeners.

Release Highlight

Fixed memory leak in Connection layer

The Connection class has recently been refactored to operate on our socket operations using promises. An oversight how we made async network operations interruptible made new promises for every operation. We've simplified the approach and corrected the leak.

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-5993-mem-leak branch 6 times, most recently from a8b3540 to cefa58f Compare March 6, 2024 22:46
@nbbeeken nbbeeken marked this pull request as ready for review March 6, 2024 23:10
src/cmap/connection.ts Outdated Show resolved Hide resolved
src/cmap/connection.ts Outdated Show resolved Hide resolved
addaleax
addaleax previously approved these changes Mar 7, 2024
src/cmap/connection.ts Outdated Show resolved Hide resolved
@baileympearson baileympearson self-assigned this Mar 7, 2024
src/cmap/wire_protocol/on_data.ts Outdated Show resolved Hide resolved
src/cmap/connection.ts Outdated Show resolved Hide resolved
@baileympearson baileympearson changed the title fix(NODE-5993): connection aborted promise leak fix(NODE-5993): memory leak in the Connection class Mar 7, 2024
@baileympearson baileympearson merged commit 69de253 into main Mar 7, 2024
22 of 26 checks passed
@baileympearson baileympearson deleted the NODE-5993-mem-leak branch March 7, 2024 17:53
aditi-khare-mongoDB added a commit that referenced this pull request Mar 8, 2024
synced new test files

added support for error response

added api docs

made MongoServerError.errorResponse required + casted resulting type errors

test(NODE-5992): fix env var restoration in tests (#4017)

refactor(NODE-5903): add newline to stdio logging (#4018)

fix(NODE-5985): throw Nodejs' certificate expired error when TLS fails to connect instead of `CERT_HAS_EXPIRED` (#4014)

test(NODE-5962): gossip cluster time in utr (#4019)

chore(NODE-5997): update saslprep to ^1.1.5 (#4023)

feat(NODE-5968): container and Kubernetes awareness in client metadata (#4005)

fix(NODE-5993): memory leak in the `Connection` class (#4022)

added TODO(NODE-XXXX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants