Skip to content

fix(microservices): do not re-create client connection once get client by service name#14869

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
mingo023:fix/do-not-recreate-client-connection-once-get-client-by-service-name
Mar 27, 2025
Merged

fix(microservices): do not re-create client connection once get client by service name#14869
kamilmysliwiec merged 1 commit intonestjs:masterfrom
mingo023:fix/do-not-recreate-client-connection-once-get-client-by-service-name

Conversation

@mingo023
Copy link
Copy Markdown
Contributor

@mingo023 mingo023 commented Mar 27, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

Memory leak potential with Grpc

I saw the method getService from client-grpc.ts always re-create client that could lead to memory potentially. Also I saw method getClientByServiceName has been implemented by not being used by anywhere.

  • 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?

My backend got issue when calling getService multiple times and I observed that memory has been increased constantly (I know that we should call getService only once when NestModule has been inited but there is exception for my codebase).

I've tested by calling thousand of grpc calls (that will call getService method) and here is the memory profiling.
image

Issue Number: N/A

What is the new behavior?

After changing createClientByServiceName by getClientByServiceName, the memory issue has been solved, no more memory increasing occur.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 0d7b9817-395d-4b5a-97ef-91b1f548a056

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 89.308%

Totals Coverage Status
Change from base Build b4e4e534-4830-4488-acbc-bed64c016714: 0.01%
Covered Lines: 7150
Relevant Lines: 8006

💛 - Coveralls

@mingo023 mingo023 changed the title fix: do not re-create client connection once get client by service name fix(microservice): do not re-create client connection once get client by service name Mar 27, 2025
@mingo023 mingo023 changed the title fix(microservice): do not re-create client connection once get client by service name fix(microservices): do not re-create client connection once get client by service name Mar 27, 2025
@kamilmysliwiec
Copy link
Copy Markdown
Member

LGTM

@kamilmysliwiec kamilmysliwiec merged commit 5bc93ea into nestjs:master Mar 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants