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

feat(microservices): add gracefull shutdown option for nats server #13924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alinowrouzii
Copy link

@alinowrouzii alinowrouzii commented Aug 28, 2024

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?

When using NATS transport for request/reply, there is no option for gracefully shutting down the server.

The NATS server close method implementation calls natsClient.close() and nullifies the client, meaning all the ongoing requests will be dropped.

Issue Number: #13920

What is the new behavior?

Two options are added to NatsOptions, gracefulShutdown and gracePeriod. If gracefulShutdown flag is provided, when calling the close method of ServerNats, first it will unsubscribe all the subscribed topics so the ServerNats will accept no new message. Also, it will wait for gracePeriod and then try to nullify the client.

When the shutdown hook is enabled, the app.close will be executed when some signal is sent to the app. The app.close first calls the server.close and in the case of ServerNats and described behavior leads to processing all ongoing requests.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build c709f725-a1f9-4942-825f-149fab1d83f1

Details

  • 14 of 17 (82.35%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 92.186%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/microservices/server/server-nats.ts 13 16 81.25%
Totals Coverage Status
Change from base Build df6d3a45-faa0-4d3b-9635-9533bb6c4560: -0.03%
Covered Lines: 6760
Relevant Lines: 7333

💛 - Coveralls

@alinowrouzii
Copy link
Author

Hey Kamil. I hope you are doing well

Any update about this pull request?
@kamilmysliwiec

Thank you.

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.

2 participants