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

Memory leak in grpc health indicator #2329

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Conversation

SophiaH67
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Currently, the grpc health indicator creates a new client and a new channel with each time the health gets checked.

This is a problem, since @grpc/grpc-js's channels reference themselves in a timeout. This means that they can NOT be garbage collected by v8(tested with NodeJS).

What is the new behavior?

New behaviour is that channels get stored on creation in a map. The key is the service name which is provided, which has to be unique anyway since it is also used as a key in the final json output. By caching the channels we prevent ourselves from creating new ones, thus fixing the memory leak.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Channels reference themselves with timeout's, meaning that they cannot
be garbage collected by v8. This is a workaround that stops us from
creating more and more channels; thus fixing a memory leak.
@SophiaH67
Copy link
Contributor Author

Some cool charts from our staging environment; guess when the change rolled out 😝

image
image
image
image

@BrunnerLivio BrunnerLivio changed the base branch from master to 10.1.x September 14, 2023 15:00
@BrunnerLivio
Copy link
Member

Really well-done investigation! Thank you so much, will release this later today 🙏

@BrunnerLivio BrunnerLivio merged commit 7667e19 into nestjs:10.1.x Sep 14, 2023
11 checks passed
BrunnerLivio pushed a commit that referenced this pull request Sep 14, 2023
Channels reference themselves with timeout's, meaning that they cannot
be garbage collected by v8. This is a workaround that stops us from
creating more and more channels; thus fixing a memory leak.

Resolves #2329
BrunnerLivio pushed a commit that referenced this pull request Sep 14, 2023
Channels reference themselves with timeout's, meaning that they cannot
be garbage collected by v8. This is a workaround that stops us from
creating more and more channels; thus fixing a memory leak.

Resolves #2329
@BrunnerLivio
Copy link
Member

Released with v10.1.0 🎉

@fmonpelat
Copy link

fmonpelat commented Sep 19, 2023

Thanks @SophiaH67!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants