Unverified Commit 7b83c19d authored by Sidharth Rathi's avatar Sidharth Rathi Committed by GitHub

Support graceful shutdowns (#36909)

## 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](https://github.com/vercel/next.js/discussions/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
parent b11d4411
...@@ -98,6 +98,29 @@ Next.js will automatically load the latest version of your application in the ba ...@@ -98,6 +98,29 @@ Next.js will automatically load the latest version of your application in the ba
**Note:** If a new page (with an old version) has already been prefetched by `next/link`, Next.js will use the old version. Navigating to a page that has _not_ been prefetched (and is not cached at the CDN level) will load the latest version. **Note:** If a new page (with an old version) has already been prefetched by `next/link`, Next.js will use the old version. Navigating to a page that has _not_ been prefetched (and is not cached at the CDN level) will load the latest version.
## Manual Graceful shutdowns
Sometimes you might want to run some cleanup code on process signals like `SIGTERM` or `SIGINT`.
You can do that by setting the env variable `NEXT_MANUAL_SIG_HANDLE` to `true` and then register a handler for that signal inside your `_document.js` file.
```js
// pages/_document.js
if (process.env.NEXT_MANUAL_SIG_HANDLE) {
// this should be added in your custom _document
process.on('SIGTERM', () => {
console.log('Received SIGTERM: ', 'cleaning up')
process.exit(0)
})
process.on('SIGINT', () => {
console.log('Received SIGINT: ', 'cleaning up')
process.exit(0)
})
}
```
## Related ## Related
For more information on what to do next, we recommend the following sections: For more information on what to do next, we recommend the following sections:
......
...@@ -129,8 +129,11 @@ if (process.versions.pnp === '3') { ...@@ -129,8 +129,11 @@ if (process.versions.pnp === '3') {
} }
// Make sure commands gracefully respect termination signals (e.g. from Docker) // Make sure commands gracefully respect termination signals (e.g. from Docker)
process.on('SIGTERM', () => process.exit(0)) // Allow the graceful termination to be manually configurable
process.on('SIGINT', () => process.exit(0)) if (!process.env.NEXT_MANUAL_SIG_HANDLE) {
process.on('SIGTERM', () => process.exit(0))
process.on('SIGINT', () => process.exit(0))
}
commands[command]() commands[command]()
.then((exec) => exec(forwardedArgs)) .then((exec) => exec(forwardedArgs))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment