feat(runtimes): a bounded close() on the Deno and Bun adapters
Closes #15, taking the second of the two answers it framed: app.close() stays Node-only, and each transport that owns a handle offers the same close({ timeoutMs }). app.close() returns at its `if (!server)` guard on Deno and Bun because they serve through app.fetch and never through listen(), and only the transport can drain what it accepted. The warning there now names the replacement instead of pointing at this issue. The runtimes do not agree, and the code says so rather than averaging them: Bun escalates. stop(false) drains, stop(true) forces, and the deadline moves between them like Node's closeAllConnections(). Deno cannot. Its two levers are mutually exclusive — aborting the serve signal while shutdown() is pending throws BadResource from Deno's own listener, uncaught and fatal under deno test. Measured on 2.9: abort alone is clean, abort after shutdown is not. So on Deno the deadline bounds how long close() waits, not when connections die, and both the type and the timeout warning say that outright. Silently accepting an option that does less is the failure mode AGENTS.md rules out. closeWithDeadline is shared so the two cannot drift into different meanings of the same timeoutMs, and it resolves on its own timer rather than awaiting the force call — Bun's stop(true) was measured waiting out a handler with a pending timer, which is exactly the unbounded wait the deadline exists to prevent. serveDeno now owns the AbortController it serves with, chaining any caller signal into it so neither party loses control; a test covers that. The Bun ambient said stop() returns void, which was simply wrong. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
6 files changed
+256
-7
No files matched your search
+7
-2
@@ -965,11 +965,16 @@ function closeApp(
|
||||
// teapot connection otherwise — so links close before we even check for a server.
|
||||
closeLinks(meshLinks);
|
||||
|
||||
// No server means the app is served through `app.fetch` rather than `listen()`, which is how
|
||||
// Deno, Bun and the edge all run. Draining is the transport's job and only the transport holds
|
||||
// the handle, so `close()` is deliberately Node-only here rather than pretending otherwise;
|
||||
// `serveDeno`/`serveBun` return a server with the same bounded `close({ timeoutMs })`.
|
||||
if (!server) {
|
||||
if (options.timeoutMs !== undefined) {
|
||||
console.warn(
|
||||
'[green-tea] close({ timeoutMs }) has no effect here — this app has no ' +
|
||||
'listen()ed server (Bun/Deno run through app.fetch). See #15.',
|
||||
'[green-tea] close({ timeoutMs }) has no effect here — this app has no listen()ed ' +
|
||||
'server. On Deno and Bun, call close() on the server serveDeno()/serveBun() returned; ' +
|
||||
'it takes the same option. On the edge the platform owns the lifecycle.',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user