# SC301: Service exited with the wrong code

> SC301 (service exited with the wrong code) means the process exited with a code other than shutdown.exitCode, or was killed by a signal. How to fix both.

Source: https://shutdown.jscrate.dev/docs/codes/sc301
Last updated: 2026-09-23

`SC301` means the service stopped in time, but its exit did not match
`shutdown.exitCode`. It may have returned a nonzero code or ended directly from
a signal.

| | |
| --- | --- |
| Code | `SC301` (FAIL) |
| Stage | Process exit |
| CLI exit code | 1 |
| What it means | The process exited, but with a different exit code than `shutdown.exitCode`, or was killed by a signal. |
| Messages | `Service process failed: <error>`<br>`Service exited with code <code> and signal <signal>; expected code <shutdown.exitCode>` |
| First thing to check | Handle SIGTERM yourself so Node does not exit with the signal, and check what sets `process.exitCode` during cleanup. |

## What does the timeline tell me?

- `code=1, signal=none` means application code set a failure exit code.
- `code=null, signal=SIGTERM` usually means there is no effective signal
  handler.
- Another signal name points to a crash or an external kill.

## How do I fix it?

Install a `SIGTERM` handler on the process that actually runs the server. Set
`process.exitCode` only when cleanup fails, and inspect stderr for the original
error.

If a nonzero exit is intentional, set `shutdown.exitCode` to that value. Most
services should still exit with `0` after a planned shutdown because process
managers treat a nonzero code as a crash.

## How do I verify the fix?

The timeline should show the configured code and `signal=none`. Also check the
service logs: a clean code with a hidden cleanup error is not a healthy
shutdown.

If `signal=SIGTERM` remains, confirm that the listener is installed on the
actual server process and not only on a parent wrapper.

## Related

- [Handle SIGTERM in Node.js](https://shutdown.jscrate.dev/docs/guides/graceful-shutdown-nodejs)
- [Exit-code configuration](https://shutdown.jscrate.dev/docs/configuration#shutdown)
- [SC300: Service did not exit](https://shutdown.jscrate.dev/docs/codes/sc300)
- [SC302: Port stayed open](https://shutdown.jscrate.dev/docs/codes/sc302)
