-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Support graceful shutdown after receiving SIGTERM signal #29959
Support graceful shutdown after receiving SIGTERM signal #29959
Conversation
process.on('SIGTERM', () => process.exit(0)) | ||
process.on('SIGTERM', () => | ||
setTimeout( | ||
() => process.exit(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway that this could be something like:
() => {
server.close();
process.exit(0);
}
Hello. Why does the introducing of this change take so long? :( It seems not to be a big deal, but it should be helpful for running Next app in Kubernetes cluster. |
@@ -94,7 +94,12 @@ if (process.env.NODE_ENV && !standardEnv.includes(process.env.NODE_ENV)) { | |||
;(process.env as any).NODE_ENV = process.env.NODE_ENV || defaultEnv | |||
|
|||
// Make sure commands gracefully respect termination signals (e.g. from Docker) | |||
process.on('SIGTERM', () => process.exit(0)) | |||
process.on('SIGTERM', () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about these listeners being omitted when an environment variable is present and instead adding custom handling for this in _document
?
This would allow more control over calling process.exit()
instead of relying on an arbitrary time value. e.g.
if (!process.env.NEXT_MANUAL_SIGTERM) {
process.on('SIGTERM', () => process.exit(0))
}
// pages/_document.js
if (process.env.NEXT_MANUAL_SIGTERM) {
// this should be added in your custom _document
process.on('SIGTERM', () => {
console.log('cleaning up')
process.exit(0)
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love this, we would like to overwrite this to close database connection ...
Handling correctly SIGTERM to gracefully shutdown the next server should be a day 1 mandatory feature. It's amazing that this is still not supported and that the only option to go with is a customized server, loosing some benefit of next (optimization) |
This comment was marked as spam.
This comment was marked as spam.
@leerob Bro you got any ideas as to why this issue is still stale? Most of us are happy to help if there's something required from the community. |
@sidwebworks we're definitely open to landing this change seems this PR has gone stale so if you would like to open a fresh one implementing the change requested here #29959 (comment) that would be great. |
## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [x] Related issues linked using [19693](#19693) - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ x] Make sure the linting passes by running `yarn lint` Closes #29959
Bug
fixes #number
contributing.md
Feature
fixes #number
Graceful shutdown #19693contributing.md
Documentation / Examples