"Not a SIGTERM handler you write" — except nothing calls close(), so every app still writes one, per runtime #70

Closed
opened 2026-08-20 18:00:10 +00:00 by chrnx · 0 comments
Owner

The README says shutdown is "an extension point, not a SIGTERM handler you write". Half of that is true. Teardown moved into the registry, which is the good half — but nothing calls close(), so every application still writes the handler, and now writes it three times because the spelling is runtime-specific.

What happens

grep -rn "SIGINT\|SIGTERM" src/ returns nothing. Same for the published dist/. No example/ calls app.close() either. The design docs (docs/plans/2026-08-17-shutdown-teardown-design.md) never mention signals — this was never decided against, it just never came up.

So an application ends up with this, which is the last thing in a green-tea entrypoint that is not framework-shaped:

// Node, Bun
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  process.on(signal, () => void app.close().then(() => process.exit(0)));
}

// Deno
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  Deno.addSignalListener(signal, () => void server.close({ timeoutMs: 5_000 }).then(() => Deno.exit(0)));
}

Why it matters

The claim in the README is what a reader acts on, and it reads as "you no longer write one". dispose() and onShutdown deliver on the content of teardown; they do not deliver on the trigger.

More to the point, this is the one remaining runtime difference in an application that has none anywhere else. In the green-desk demo the three entrypoints are otherwise identical apart from the boot call — app.listen vs serveDeno vs serveBun — which is the framework's whole pitch. Then the signal block differs too: process.on on two runtimes, Deno.addSignalListener on the third, process.exit vs Deno.exit. Absorbing exactly that kind of difference is what green-tea is for.

Getting it wrong is quiet, too: forget it and the container is SIGKILLed after the grace period, every dispose() the registry so carefully ordered never runs, and nothing reports it. The feature added in 26.8.0-beta.1 silently does not happen.

Scope

Opt-in, because a framework that installs process-wide signal handlers behind your back is worse than one that installs none — a library has no business deciding when the process exits:

  • createApp({ handleSignals: true }), or app.handleSignals(), registering SIGINT/SIGTERM to call close() and then exit, using the right API per runtime (Deno.addSignalListener where process is absent, nothing on the edge).
  • Return an unregister function, and be idempotent — a second signal while draining should not start a second close.
  • If this is a deliberate "not our job", then the README sentence needs to change: teardown is an extension point, and triggering it is still yours. Right now the sentence promises the whole thing.

Related

Found while consolidating the Node/Deno/Bun demos into one folder — the signal block was the only place left where the shared code could not stay shared.

The README says shutdown is *"an extension point, not a `SIGTERM` handler you write"*. Half of that is true. Teardown moved into the registry, which is the good half — but nothing calls `close()`, so every application still writes the handler, and now writes it three times because the spelling is runtime-specific. ## What happens `grep -rn "SIGINT\|SIGTERM" src/` returns nothing. Same for the published `dist/`. No `example/` calls `app.close()` either. The design docs (`docs/plans/2026-08-17-shutdown-teardown-design.md`) never mention signals — this was never decided against, it just never came up. So an application ends up with this, which is the last thing in a green-tea entrypoint that is not framework-shaped: ```ts // Node, Bun for (const signal of ['SIGINT', 'SIGTERM'] as const) { process.on(signal, () => void app.close().then(() => process.exit(0))); } // Deno for (const signal of ['SIGINT', 'SIGTERM'] as const) { Deno.addSignalListener(signal, () => void server.close({ timeoutMs: 5_000 }).then(() => Deno.exit(0))); } ``` ## Why it matters The claim in the README is what a reader acts on, and it reads as "you no longer write one". `dispose()` and `onShutdown` deliver on the *content* of teardown; they do not deliver on the trigger. More to the point, this is the **one remaining runtime difference** in an application that has none anywhere else. In the `green-desk` demo the three entrypoints are otherwise identical apart from the boot call — `app.listen` vs `serveDeno` vs `serveBun` — which is the framework's whole pitch. Then the signal block differs too: `process.on` on two runtimes, `Deno.addSignalListener` on the third, `process.exit` vs `Deno.exit`. Absorbing exactly that kind of difference is what green-tea is for. Getting it wrong is quiet, too: forget it and the container is SIGKILLed after the grace period, every `dispose()` the registry so carefully ordered never runs, and nothing reports it. The feature added in `26.8.0-beta.1` silently does not happen. ## Scope Opt-in, because a framework that installs process-wide signal handlers behind your back is worse than one that installs none — a library has no business deciding when the process exits: - `createApp({ handleSignals: true })`, or `app.handleSignals()`, registering SIGINT/SIGTERM to call `close()` and then exit, using the right API per runtime (`Deno.addSignalListener` where `process` is absent, nothing on the edge). - Return an unregister function, and be idempotent — a second signal while draining should not start a second close. - If this is a deliberate "not our job", then the README sentence needs to change: teardown is an extension point, and *triggering* it is still yours. Right now the sentence promises the whole thing. ## Related Found while consolidating the Node/Deno/Bun demos into one folder — the signal block was the only place left where the shared code could not stay shared.
chrnx closed this issue 2026-09-04 13:32:27 +00:00
Sign in to join this conversation.