Bound hub shutdown drain with a timeout and error reporting - #446
Merged
TheGreatAxios merged 3 commits intoAug 29, 2026
Merged
TheGreatAxios merged 3 commits into
TheGreatAxios merged 3 commits into
Conversation
TheGreatAxios
force-pushed
the
cl-7133-hub-shutdown-awaits-eight-closes-with-no-timeout-or-catch-a
branch
from
August 28, 2026 15:28
5128a61 to
7dd88c7
Compare
Covers drainWithTimeout's drained/timed-out/failed outcomes and shutdownHub's exit-code and reportError wiring for each, with injected exit/report callbacks and short timeouts so the suite runs in milliseconds.
Hub shutdown previously awaited hub.close()'s eight sequential closes with no timeout: a hung close blocked SIGTERM exit forever, and a rejection was unhandled. shutdownHub now bounds the drain to 10s and always exits — 0 on a clean drain, non-zero with the cause reported through reportError on a throw or timeout — mirroring the sidecar's drainWithTimeout shape as a local copy rather than a shared import, since the two apps diverge on timeout exit semantics. Fixes CL-7133.
Bun's Server.stop waits for open connections and websockets by default, so leaving it outside the bounded drain kept the hang CL-7133 was filed against, one line earlier.
TheGreatAxios
force-pushed
the
cl-7133-hub-shutdown-awaits-eight-closes-with-no-timeout-or-catch-a
branch
from
August 29, 2026 04:46
7dd88c7 to
5c55ae1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes CL-7133 — https://linear.app/abklabs/issue/CL-7133
Problem
apps/hub/src/index.ts(~3444-3452) hadshutdown = async () => { await server.stop(); await hub.close(); process.exit(0); }invoked asvoid shutdown()from SIGINT/SIGTERM.hub.close()awaits eight sequential closes with no bound — a hung close blocks process exit until SIGKILL, and a rejection is an unhandled rejection rather than a reported error.Change
apps/hub/src/shutdown.ts: new hub-local module withdrainWithTimeout(a local copy ofapps/sidecar/src/shutdown.ts's primitive — not imported, since the two apps diverge on timeout exit semantics: the sidecar treats a timeout as a clean-enough exit, the hub treats it as a fault) andshutdownHub, which drains within an injectable bound, exits 0 on success, and on a throw or timeout reports the cause throughreportError(@corbits/error-sink) and exits non-zero.apps/hub/src/index.ts: wiresshutdownHubaroundhub.close()with a 10s bound, replacing the unboundedawait hub.close().Tests
apps/hub/src/shutdown.test.ts(red/green):drainWithTimeout's drained/timed-out/failed outcomes, andshutdownHub's exit code +reportErrorcall for each case, using injectedexit/reportcallbacks and millisecond-scale timeouts (no real waits).bun test apps/hub/src/shutdown.test.ts— 6 pass.Note on the gate
bun run checkwas OOM-killed mid-run on this shared machine (1-min load average ~30-40 throughout), unrelated to this change. Ran the focused gates instead:apps/hubpackagetsc --noEmitclean,bun test apps/hub/src/shutdown.test.tspassing,prettier --write+eslintclean on all changed files. CI is the gate for the full suite.