-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Manual Graceful shutdowns do not work #56810
Comments
We noticed the same issue and found out that Next.js has added SIGTERM and SIGINT handlers in many places, for example: // node_modules/next/dist/server/lib/router-server.js
if (!process.env.__NEXT_PRIVATE_CPU_PROFILE) {
process.exit(0);
} // node_modules/next/dist/server/lib/start-server.js
process.on("SIGTERM", ()=>cleanup(0)); Without patching Next.js, the only ugly hack we could get work is this: // Add to _document.jsx
if (process.env.NEXT_MANUAL_SIG_HANDLE) {
const originalExit = process.exit;
process.exit = function (code) {
console.log(`Exit called with code: ${code}`);
};
process.on('SIGTERM', () => {
console.log('Received SIGTERM. Starting graceful shutdown...');
// Simulate a graceful shutdown delay
setTimeout(() => {
console.log('Graceful shutdown complete.');
originalExit(0);
}, 5000);
});
} |
follow, hit the same issue |
ztanner
added a commit
that referenced
this issue
Dec 1, 2023
If a manual signal handler is registered, SIGINT and SIGTERM should not be handled by Next.js. This was already the case in the standalone server.js but was missing here, rendering the env flag useless. With this fix, the example given in https://nextjs.org/docs/pages/building-your-application/deploying#manual-graceful-shutdowns is working (again). Fixes #56810. Co-authored-by: Zack Tanner <zacktanner@gmail.com>
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
# for free
to subscribe to this conversation on GitHub.
Already have an account?
#.
Link to the code that reproduces this issue
https://github.com/higgins/next13-graceful-shutdown-bug
To Reproduce
SIGINT
orSIGTERM
to the running server and observe noReceived SIGINT: cleaning up
orReceived SIGTERM: cleaning up
message loggedCurrent vs. Expected behavior
Following steps 1-5 in previous section, I expect to see
Received SIGINT: cleaning up
orReceived SIGTERM: cleaning up
message logged after sendingSIGINT
orSIGTERM
to the current server.Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6020 Binaries: Node: 18.17.1 npm: 9.6.7 Yarn: N/A pnpm: 8.7.5 Relevant Packages: next: 13.5.5-canary.13 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: N/A Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure, App Router
Additional context
We see the expected log message
Received SIGINT: cleaning up
only at build timeThe run-time event handler is not attached.
The text was updated successfully, but these errors were encountered: