Exit next dev when the server process is killed by a signal (#101752)
## Summary
When the server child process of `next dev` exited because of a
**signal** (for example SIGKILL from the OOM killer, or SIGSEGV), the
`next dev` parent returned from its `exit` handler without logging,
exiting with an error, or restarting. Depending on the environment it
then either kept running without a server or, once its event loop
drained, exited silently with code `0`. Anything waiting on `next dev`,
such as a user or the e2e test harness (which only watches the `next
dev` process and ignores a code-0 exit), would then hang or fail far
from the cause.
Now, unless the parent is already stopping or an upgrade prompt is in
progress (both unchanged):
- For **SIGKILL, SIGSEGV, SIGABRT and other non-termination signals**,
`next dev` logs an error naming the signal and exits with `128 + signal
number` (e.g. `137` for SIGKILL), the conventional shell code:
```
тип The Next.js dev server process exited unexpectedly due to signal
SIGKILL. This can happen when the system runs out of memory.
```
The memory hint only appears for SIGKILL.
- For **SIGINT, SIGTERM and SIGHUP**, `next dev` exits with `128 +
signal number` without an error. These are termination requests rather
than crashes, e.g. Ctrl+C arriving before the server installed its own
signal handlers.
Why the existing intentional cases are unaffected:
- Shutdowns started by the parent (Ctrl+C, SIGTERM, including the
SIGKILL fallback after `NEXT_EXIT_TIMEOUT_MS`) are still filtered out by
`sessionStopHandled`, which is set before the parent signals the child.
Their exit codes don't change.
- The server handles SIGINT/SIGTERM itself and exits with *codes*
130/143. Restarts use `RESTART_EXIT_CODE`. Neither goes through the
signal path.
- There is no automatic restart, matching how an unexpected non-zero
exit code is already handled.
Motivation: canary CI saw dev-mode jobs in `test/e2e/app-dir/actions`
hang until the job timeout without a local reproduction. One hypothesis
is that the server process was killed by a signal under memory pressure
and the silent parent hid it. This change makes that failure visible and
fail fast, and it's worthwhile even if it doesn't explain every hang.
Related: #101724 (diagnostics for the same investigation).
## Verification
- New `test/development/app-dir/dev-server-child-signal-exit`: starts
`next dev`, gets the server process pid from a route handler, SIGKILLs
it, then waits for `next dev` to exit and asserts code `137` plus the
logged error. It doesn't use sleeps. Before this change it fails with
`Expected: 137, Received: 0`. It passes on Turbopack and webpack.
- `pnpm test-dev-turbo test/e2e/cli/cli.test.ts`: passes.
- Manual checks:
- SIGSEGV to the server process: error logged, exit code `139`.
- SIGTERM to the server process with `NEXT_MANUAL_SIG_HANDLE=1`: exit
code `143`, no error.
- SIGINT to `next dev`: unchanged exit code `0`, no error.
<!-- NEXT_JS_LLM -->
<!-- fleet ea3bb25f-9cbd-4071-9c37-589af9a26a54 -->
Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>