docs: describe the shutdown deadline, and who owns it per runtime
Closes #18. The three places that still described close() without a timeout — the createapp reference table, the README bullet and the dependency-injection inline comment — now say that in-flight work gets 10 seconds, then a warning and a force-close. Also documents what #18 deliberately deferred, now that #15 has decided it. runtimes.md gains the per-runtime story: app.close() is Node-only, the servers serveDeno()/serveBun() return carry the same close({ timeoutMs }), and edge has nothing to close. Including the row that matters — Node and Bun cut the remainder after the deadline, Deno returns and lets the process end it — since a deadline that means two things is worse than one that admits it. createApp({ shutdownTimeoutMs }) from #19 gets its row in the options table. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+31
-3
No files matched your search
@@ -53,7 +53,8 @@ const app = createApp({ modules: [ApiModule] });
|
||||
await app.listen(3000);
|
||||
// GET /api/users/9 (header x-token) → { "requested": "9", "you": { "id": "...", "name": "Diego" } }
|
||||
|
||||
await app.close(); // graceful shutdown: drains in-flight requests, closes streams + mesh links
|
||||
await app.close(); // graceful shutdown: drains in-flight, closes streams + mesh links,
|
||||
// then force-closes whatever is left after 10s — app.close({ timeoutMs })
|
||||
```
|
||||
|
||||
## `@Provider` — app-scope, memoized
|
||||
|
||||
@@ -41,6 +41,32 @@ destroys excess sockets without sending an HTTP response. `Deno.serve` and `Bun.
|
||||
equivalent active-socket cap, so `serveDeno` and `serveBun` cannot enforce this option. Apply the
|
||||
connection limit at the deployment platform or reverse proxy on those runtimes.
|
||||
|
||||
**Shutdown belongs to whoever owns the server.** `app.close()` is Node-only. On Deno and Bun the
|
||||
app is served through `app.fetch` and never through `app.listen()`, so `app.close()` has no server
|
||||
to drain and returns immediately — it warns if you passed `timeoutMs`. The server `serveDeno()` and
|
||||
`serveBun()` return carries the same `close({ timeoutMs })` instead:
|
||||
|
||||
```ts
|
||||
const server = serveBun(app, { port: 3000 }); // or serveDeno(app, { port: 3000 })
|
||||
await server.close({ timeoutMs: 5_000 });
|
||||
```
|
||||
|
||||
On Cloudflare Workers there is nothing to close: `edgeHandler` is a handler, not a server, and the
|
||||
platform owns the lifecycle.
|
||||
|
||||
One difference the deadline cannot hide:
|
||||
|
||||
| Runtime | After the deadline |
|
||||
|---|---|
|
||||
| Node | warns, then `closeAllConnections()` — the remainder is cut |
|
||||
| Bun | warns, then `stop(true)` — the remainder is cut |
|
||||
| Deno | warns, then **returns anyway**; the remainder ends with the process |
|
||||
|
||||
Deno offers no force-close that composes with a drain already under way — aborting the signal its
|
||||
server was started with throws `BadResource` once `shutdown()` is pending. So on Deno the deadline
|
||||
bounds how long `close()` waits, not when the connections die. Exit the process after `close()`
|
||||
resolves and the effect is the same; keep serving and it is not.
|
||||
|
||||
**Body-size enforcement differs slightly:** on `app.fetch`, an oversized body is read in full
|
||||
before the `413` is returned, whereas Node aborts mid-stream once the limit is hit — so on
|
||||
non-Node runtimes, also bound request size at the platform/runtime layer.
|
||||
|
||||
@@ -26,6 +26,7 @@ const app = createApp(options);
|
||||
| `views` | `string` | `process.cwd()` | base dir `@Html('file.html')` paths resolve against — relative paths join it, absolute paths are used as-is ([HTML & views](/docs/guides/html/)) |
|
||||
| `viewEngine` | `(source: string, data: unknown) => string` | built-in `render` | swap in your own template engine for `@Html(..., { template: true })`; template mode only ([HTML & views](/docs/guides/html/)) |
|
||||
| `static` | `boolean \| string` | — | serve a directory as a `GET`/`HEAD` fallback (after declared routes, before `404`); `true` → `./public`, a string → that dir; path-traversal-safe; needs a filesystem — Node/Deno/Bun only ([HTML & views](/docs/guides/html/)) |
|
||||
| `shutdownTimeoutMs` | `number` | `10_000` | how long `close()` gives in-flight work before forcing the rest shut; `close({ timeoutMs })` still wins per call. Set it here when `close()` is reached from a signal handler or shutdown hook you do not own ([runtimes](/docs/guides/runtimes/)) |
|
||||
| `mesh` | `MeshConfig` | — | distributed DI — **requires `experimental: true`** ([mesh](/docs/guides/mesh/)) |
|
||||
| `experimental` | `boolean` | `false` | opt in to alpha features (currently gates `mesh`) |
|
||||
| `warnGraphDepth` | `number \| false` | `20` | warn when one route resolves to more than this many steps; `false` disables the design warning |
|
||||
@@ -64,7 +65,7 @@ const app = createApp(options);
|
||||
| Member | Returns | Notes |
|
||||
|---|---|---|
|
||||
| `listen(port)` | `Promise<http.Server>` | boots providers, then serves |
|
||||
| `close()` | `Promise<void>` | drains in-flight, closes streams + mesh links |
|
||||
| `close({ timeoutMs? })` | `Promise<void>` | drains in-flight, closes streams + mesh links; after the deadline (default `10s`, or `createApp({ shutdownTimeoutMs })`) it warns and force-closes what is left. Node-only — see [runtimes](/docs/guides/runtimes/) |
|
||||
| `ready()` | `Promise<void>` | resolves the graph and mesh links without booting providers |
|
||||
| `fetch(request)` | `Promise<Response>` | Web-Standards HTTP/SSE handler for Node, Deno, Bun, and edge |
|
||||
| `upgrade(request, socket)` | `Promise<void>` | neutral WebSocket upgrade used by non-Node adapters |
|
||||
|
||||
Reference in new issue
Block a user