feat(http): liveness and readiness probes with a drain window (CARD-17, #115)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / build (pull_request) Successful in 27s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 14s

createApp({ health: true }) serves GET/HEAD /__live__ and /__ready__.
Ready reports booting until boot() resolves, ok or degraded (from
app.degraded()) after that, and draining from the moment close() starts.

Probes are answered by the adapters, ahead of the request gate and of
handle(): Node in serve() (src/http/server.ts), the Fetch path in
app.fetch before it awaits the boot. Otherwise ready could never say
booting. Being ahead of the gate means maxConcurrentRequests never sheds
a probe (D14). Being ahead of handle() means no step, provider, plugin or
onError runs, and no lifecycle event is emitted, so logRequests and
metrics never see a probe. Security headers still apply, plus
cache-control: no-store. Other methods get 405 with Allow: GET, HEAD.

A probe through app.fetch before any boot starts the boot without
awaiting it. On the edge, or under a bare Deno.serve(app.fetch), nothing
else may boot the app, and an orchestrator that waits for ready before
sending traffic would wait forever.

health: { drainDelayMs } (D14) marks the app draining and keeps the
listener open for that long before connections drain. Without it, Node
closes idle keep-alive sockets at once, and a probe sees a reset rather
than the 503. The window is spent out of the close budget. serveDeno and
serveBun start the same window, through a symbol-keyed hook on the app,
before server.shutdown() / server.stop(false). workerd has no close(),
so it never reports draining.

While health is on, /__live__ and /__ready__ join the reserved-path
boot check that CARD-21 introduced, for local and mesh-spliced routes.
Invalid health values throw at createApp.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-23 00:54:04 -05:00
1 parent 9977d14605
commit ba57568a84
15 files changed
+789 -10

No files matched your search

+20 -1
View File
@@ -171,8 +171,27 @@ async function main() {
assert.equal(reservedRes.status, 500);
assert.match(await reservedRes.text(), /^route @Ws \/__mesh__\/control at Claims\.control uses the reserved path/);
// CARD-17 T10: live 200; ready booting → ok, with only probes reaching the isolate. There is no
// close() on workerd, so draining is never reported here (documented, not tested for). Any probe
// starts the boot, so ready is asked first to see `booting`.
const first = await mf.dispatchFetch('http://health/__ready__');
assert.equal(first.status, 503);
assert.deepEqual(await first.json(), { status: 'booting' });
const live = await mf.dispatchFetch('http://health/__live__');
assert.equal(live.status, 200);
assert.deepEqual(await live.json(), { status: 'ok' });
let ready = await mf.dispatchFetch('http://health/__ready__');
for (let i = 0; i < 20 && ready.status !== 200; i++) {
await ready.arrayBuffer();
await new Promise((resolve) => setTimeout(resolve, 25));
ready = await mf.dispatchFetch('http://health/__ready__');
}
assert.equal(ready.status, 200);
assert.deepEqual(await ready.json(), { status: 'ok' });
assert.equal(ready.headers.get('cache-control'), 'no-store');
console.log(
'edge (workerd via miniflare): HTTP 200 + body limits 413/413/200/413 + WS echo:hi + ws limits + cf-connecting-ip under trustProxy + reserved path — PASS',
'edge (workerd via miniflare): HTTP 200 + body limits 413/413/200/413 + WS echo:hi + ws limits + cf-connecting-ip under trustProxy + reserved path + health — PASS',
);
} finally {
await mf.dispose();