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

chore(core): defer application shutdown until init finishes #14139

Conversation

mksony
Copy link
Contributor

@mksony mksony commented Nov 14, 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:

Not fully sure if this is a bugfix or feature. I guess one could argue in both directions.

What is the current behavior?

If you use lifecycle methods during startup of the nestjs applications with async operations with calls e.g. to the database, message/job processing and you receive a SIGTERM signal it can happen that the connections required for the async operations are closed while executing those async operations. For us this happened now and then in our K8s cluster where the process can be terminated at any time. That can lead to unexpected errors.

Issue Number: N/A

What is the new behavior?

When a shutdown is requested via the incoming termination signal, the application defers calling the shutdown hooks until the app is fully initialized.

Does this PR introduce a breaking change?

  • [] Yes
  • No

Other information

@mksony mksony force-pushed the chore/ensure-application-init-before-accepting-sigterm branch 3 times, most recently from e982781 to 3522c4d Compare November 14, 2024 12:39
@mksony mksony force-pushed the chore/ensure-application-init-before-accepting-sigterm branch from 3522c4d to 5c6986f Compare November 14, 2024 12:50
@kamilmysliwiec kamilmysliwiec merged commit dade6d5 into nestjs:master Nov 15, 2024
@kamilmysliwiec
Copy link
Member

LGTM

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.

2 participants