Repository navigation
Conversation
…ect loop for good The connection supervisor's reconnect loop ran as one forked fiber with nothing around it. A defect or a stray interruption in it ended the fiber silently. The state stayed where it was and Retry did nothing. One route real code takes: a session's `closed` can fail with a cause that mixes a failure with an interruption, and `exitUnlessInterrupted` turned any cause holding an interruption into an interruption of the loop. The loop now survives all of that: - `runAttempt` uses `Effect.exit` where it used `exitUnlessInterrupted`, so a stray interruption becomes a failed attempt that keeps whether the session was live and stable. - A defect elsewhere in an attempt is caught around the attempt, logged, and retried on the normal backoff ladder. - A defect from closing an attempt's scope is logged as a failed release, and the attempt's outcome stands. - The generation number advances where the session is published as connected, so no lost outcome or restart gives two sessions the same number. - A defect in the loop outside an attempt is logged, and the loop restarts after the longest retry delay or the next signal. - The shutdown finalizer is registered before the fibers, so closing a supervisor does not look like a failure to the loop. A failure inside the restart handler itself still ends the loop, after one log line. The supervisor's other background fibers are unchanged.
…ingdotgg#39393) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Closing without merging here. The fix landed upstream as pingdotgg#39420, squash-merged as |
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 #16.
Filed upstream as pingdotgg#39420, for the upstream issue pingdotgg#39418. The follow-up #39 is upstream as pingdotgg#39419, and a maintainer's PR, pingdotgg#39431, fixes it.
The connection supervisor keeps a connection alive with one loop: try to connect, wait, try again. That loop ran as a single background fiber with nothing around it. A defect or a stray interruption anywhere in it ended the fiber silently. The app kept showing its last state, and Retry did nothing, because nothing was left to hear it.
The issue knew of no real trigger. There is one.
rpc/session.tsfails a session'sclosedwith whatever cause ended the config subscription, unless that cause holds interruptions only. A cause that holds a failure and an interruption gets through, andexitUnlessInterruptedturned any cause holding an interruption into an interruption of the loop.What changes
runAttemptusesEffect.exitwhere it usedexitUnlessInterrupted, and that helper is gone. A stray interruption becomes a failed attempt that keeps what the attempt knows: whether the session was live and whether it was stable. A typed error mixed with an interruption keeps its typed error, so a blocked host stays blocked. Effect does not run the continuation of a fiber that is itself interrupted, so a real shutdown still ends the loop.Effect.acquireUseRelease. A defect from closing it is logged as a failed release, and the attempt's outcome stands. If it replaced the outcome, a release that throws after a requested disconnect would show backoff, and a Retry would wait out the ladder's current delay.The issue proposed only the restart where the loop is forked. That alone would send every attempt defect, the issue's own example included, through the five-minute wait and reset the retry ladder. So attempts handle their own failures, and the restart is the last resort.
New log lines
One error line per unexpected failure:
Connection <attempt | release | loop> failed with an unexpected <defect | interruption>.It carries the environment and a reason count. For a defect it also carries the first defect's name and stack, through the existing safe-attributes helper. It never carries the error's message.Main had only the attempt-defect line, and only while connecting. New here: a defect in the connected phase, a defect beside a typed failure in the same cause, every interruption line, and the release and loop lines. A release defect while a supervisor shuts down is logged too.
Proof
The real route, in the running app
reconnect-survives-config-stream-failing-while-interrupted.e2e.tsis part of this PR. It opens a thread, then hands the app one server frame that ends the config subscription with a typed failure and an interruption in the same cause. The frame is injected from the page. I found no way to make a real server send it. Everything after the frame is the app's own code.Five seconds after the frame, the scenario types a message and presses Enter. These are three seconds later:
57db750b8f89017c15a0Both runs side by side:
real-route-before-after.mp4
The issue's own example, in the running app
A second scenario does what the issue describes. It closes the app's socket from the page, as a network drop would, and makes the next read of
navigator.onLinethrow once. No real browser throws there, so this scenario is not part of the PR. Its code and the reproduction on main are in this comment on the issue.scenarios:provegives the same verdict: it fails on base57db750b8fand passes on head89017c15a0. Ten seconds after the drop, the scenario presses Retry now if the button is there:57db750b8f89017c15a0network-status-before-after.mp4
On head the page logged one line:
ERROR: Connection attempt failed with an unexpected defect.On base it logged nothing. A control run of the same scenario with no injected throw reconnected on main's supervisor, so the stuck state comes from the defect and not from the dropped socket.Tests
The new and changed cases, run with main's
supervisor.tsand with this branch:All eleven fail on base because the loop is dead and the state never changes. The two "stops attempting when its scope closes" cases pass on base on purpose. They guard the finalizer order, and they fail if the finalizer is registered after the fibers again.
vp test run src/connectionpasses, 214 of 214.vp run check:changedpasses.Not covered
Implemented by Claude Fable 5.2 and Claude Opus 5.5 in Claude Code (T3 Code). Reviewed by Claude Opus 5.5 and GPT-6.1 Sol.