Repository navigation
fix(broker): keep a silent hub from wedging the native broker - #301
Merged
Merged
Conversation
hibernate and machine_wake awaited the hub's reply under the core lock with no time limit, so a hub that went quiet on an open socket blocked every request and SIGTERM. Hub work now runs after the core is released, every hub request is bounded at 15 s and hangs up a silent socket, shutdown no longer waits on a busy core, and a watchdog logs a core held past 30 s. The TypeScript bridge gets the same reply limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: GPT 6.1 Sol <codex@openai.com>
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.
TL;DR
Summary
hibernateandmachine_wakeused to wait for the hub's reply while holding the core lock, and nothing bounded that wait. Every later request queued behind them forever, and SIGTERM was ignored too.hibernateandmachine_wakenow leave their hub work as aHubJob, whichCore::executeruns after it releases the core. The hibernate mirror keeps the TypeScript broker's 10 s barrier, and the wakers are still kicked after the push.forwardstill waits under the core, but every attempt and every backoff now fits insideforward_wait.daemon stopfinishes inside its 5 s window.replyTimeoutMs) on its hub requests. It never had the wedge, because it has no global lock, but a silent socket was never torn down either.Root cause
Bridge::request(crates/scp-broker/src/bridge/link.rs) awaited the hub's reply on a oneshot with no timeout. The waiter only failed once the socket closed.Core::hibernate_rpc→bridge_mirror→mirror_now(hibernate.rs:287) andCore::machine_wake(bridge/mod.rs:241) awaited it while holding the core lock taken inserve_connection. Picture a hub that answers the bridge'shelloand then goes quiet on a live socket, for example while it is overloaded or flapping. Ahibernatefrom the periodic claude-bg task then holds the core forever. The claude-bg task itself hangs, and the broker kills it after 600 s, but the server-side request keeps the lock.Broker::runbegan shutdown withself.core.lock().await, so SIGTERM hung behind the same lock.The hub flapping triggered the hang. The unbounded await under the lock was the cause.
Test plan
crates/scp-broker/tests/bridge_stall.rsuses a fake hub that links and then goes silent. On main, both tests fail: the broker stops answering while ahibernatewaits on the hub, and SIGTERM does not stop it while amachine_wakewaits. With this change, both pass.server::tests::shutdown_finishes_while_a_request_holds_the_core: shutdown finishes while a stalled store write holds the core.packages/broker/src/bridge-silent.test.ts: a request the silent hub never answers fails in time, and the socket is linked again. It times out on main.cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspaceSCP_BROKER_WAKERS=1bunx biome ci .,bun run lint,bun run typecheck,bun scripts/relay-version.ts --check,bun scripts/native-changeset.ts --base origin/main🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Co-Authored-By: GPT 6.1 Sol codex@openai.com