mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## What? Use signal-based exit codes when shutting down the Next.js server to prevent the process from waiting for the debugger to disconnect. ## Why? When Node.js devtools are attached (via `--inspect` flag or the Next.js DevTools "Attach debugger" feature), pressing Ctrl+C causes the dev server to hang instead of exiting immediately. This happens because calling `process.exit(0)` makes Node.js treat it as a normal exit, which waits for all debuggers to disconnect before terminating. In contrast, plain Node.js terminates immediately on SIGINT even with a debugger attached, because signal-based termination doesn't wait for debuggers. ## How? Instead of calling `process.exit(0)` after cleanup, use signal-based exit codes: - SIGINT (signal 2) → `process.exit(130)` (128 + 2) - SIGTERM (signal 15) → `process.exit(143)` (128 + 15) This tells Node.js the process was terminated by a signal, which avoids the debugger wait behavior. Changes: - Modified the cleanup function to accept the signal that triggered it - Use `process.exit(signal === 'SIGINT' ? 130 : 143)` instead of `process.exit(0)` - Removed the previous `inspector.close()` workaround as it's no longer needed --------- Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>