Skip to Content
Senri

Graceful shutdown

On SIGTERM, stop after waiting for in-flight requests

import {  } from "@senrijs/senri/serve";

await (, {
    : 30_000,     // wait up to 30 seconds for in-flight requests
    : () => .(),
});

On SIGTERM or SIGINT, serve() stops in this order:

  1. Makes /readyz of health() return 503 (so that load balancers stop sending new requests)
  2. Stops accepting new connections and waits for in-flight requests (shutdownTimeout, 10 seconds by default; after that, the remaining connections are cut)
  3. Calls onShutdown, then exits the process

A second signal while waiting exits at once (for example, pressing Ctrl+C twice).

Stop it yourself

server.stop() stops the same way (steps 1 and 2). Use it to clean up after tests and so on.

import {  } from "@senrijs/senri/serve";

const  = await (, { : 0 });
// ...
await .();

Leave it to the runtime

To keep the runtime's default behavior, set gracefulShutdown: false. Then serve() does nothing on signals.

  • Deno has no way to cut the remaining connections after it stops waiting. After shutdownTimeout, Senri stops waiting, and the connections are cut when the process exits

On this page