Repository navigation
fix(web): settle RPCs parked on reconnect readiness - #1738
Merged
Merged
Conversation
An RPC awaiting the `ready` promise during a failed CONNECTING attempt, a close(), or a socket that dies between readiness and send could sit in `pending` forever: close() resolved `ready` so waiters resumed onto a dead socket where send() silently drops, and a reconnect callback already awaiting URL discovery could still create a fresh socket and pending `ready` after dispose. close() now rejects `ready` so parked and late RPCs fail fast, rpc() and rpcBinary() reject when the socket is no longer OPEN after `await ready`, the in-flight reconnect callback bails if closed during discovery, and waitForConnection propagates the rejection. Fixes #1733
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.
What
ws-transportparked RPCs on areadypromise that could leave them unsettled forever. The original orphan (reconnect replacing a pendingready) was already fixed by thereadyPendingguard in #1736; this PR closes the remaining gaps against #1733's acceptance criteria.close()now rejectsreadywithTransport closedinstead of resolving it. Previously parked RPCs resumed onto a CLOSED socket wheresend()silently drops the frame, leaving the request inpendingforever. Late RPCs issued after close now reject instead of queueing onto a dead transport.rpc()andrpcBinary()reject withWebSocket disconnectedwhen the socket is no longer OPEN afterawait ready(covers the open-then-close-before-continuation race and the post-close call path). The readiness policy is now identical on the JSON and binary paths.close()lands while it is awaitingdiscoverServerUrl; previously it still ranconnect(), leaking a socket and re-arming a fresh pendingreadythat would park future RPCs forever.waitForConnectionpropagates thereadyrejection instead of hanging until timeout.Why
Fixes #1733. An operation awaiting readiness could hang forever even after the app reported connectivity restored; on the audited commit the parked RPC was still pending after reconnect + 60s.
Evidence
Regression coverage lives in
apps/web/src/__tests__/connection.test.tsunder the normal Vitest config (7 new tests). The fixture models real browser semantics:send()throws while CONNECTING and silently discards while CLOSED, which is what made the close-path orphans reproducible.pendingpast 60s of fake time.connection.test.ts, 38/38 in the sibling transport suites (agent-commands,thread-reconnect-refresh,terminal-reconnect-selection,running-session-hydrate,ws-events); oxlint andtsc --noEmitclean forapps/web.fixture-repowhile reconnecting solistThreadsparked onready, killed the next socket while CONNECTING (readyState === 0confirmed), next attempt opened, the parked RPC resumed and the project expanded to "No active threads". Zero console errors.Review Notes
No automatic retries were added; already-sent requests still settle only via response or
rejectPending, so mutations cannot be duplicated by the transport. The verification boundary matches the issue's: deterministic fake-socket coverage plus a live reconnect drive; no real network fault injection claimed.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.