# SC312: Work finished too soon to test rejection

> SC312 (work finished too soon to test rejection) means in-flight work ended before the new request could be sent during drain. Use a longer-running workload.

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

`SC312` means the active workload ended before shutdown-check could send the
new request. Without older work still draining, the test cannot prove how the
service handles traffic during a drain.

| | |
| --- | --- |
| Code | `SC312` (FAIL) |
| Stage | Draining traffic |
| CLI exit code | 1 |
| What it means | The in-flight work had already finished when the new request was due, so rejection during drain could not be observed. |
| Message | `Work finished before new-request rejection could be checked; use a longer-running workload` |
| First thing to check | Use a longer-running test workload, so old work is still draining when the new request is sent. |

## How do I fix it?

1. Make the controlled workload run longer.
2. Withdraw readiness immediately after `SIGTERM`.
3. Remove unnecessary delays before changing the readiness state.
4. Keep the new-request route fast enough to return before the deadline.

The workload should stay active long enough for readiness polling and the new
request, but still finish comfortably before `shutdown.deadlineMs`.

Do not disable the rejection check merely to hide the timing problem. If your
production platform can route traffic during shutdown, keep the check and make
the test window reliable.

## How do I verify the fix?

The corrected order is `readiness withdrawn`, then `new request rejected`,
then `work request finished`. Run several times on CI to confirm the old work
does not finish first under load.

If readiness withdrawal itself is slow, fix that state change rather than
adding an excessive artificial delay to the workload.

## Related

- [Test traffic draining](https://shutdown.jscrate.dev/docs/guides/readiness-and-draining)
- [Choose an in-flight workload](https://shutdown.jscrate.dev/docs/in-flight-work)
- [SC311: New request accepted](https://shutdown.jscrate.dev/docs/codes/sc311)
