Repository navigation
fix(io): notice a silently dead connection on wall-clock time (#309) - #325
Merged
Merged
Conversation
`connStallTimeout` was evaluated in exactly one place, the read loop's forward wait, so a transport that died while the sliding window could still serve reads was detected only once a consumer happened to block on it. In the field report `bytesFetched` sat frozen for 4.5 minutes across a pause. The transport does not cover that gap either: the persistent request runs with `timeoutInterval = 0` on purpose, so the reader is the only detector there is. A delivery-gap watchdog now ends a generation that has an installed transfer and no delivery for `connStallTimeout`, whether or not a read is waiting on it, and names the gap in the log. Same threshold and same action as the read-side wait: the only thing removed is the accidental exemption for a well-buffered reader. It only ENDS. Opening connections stays with the read thread, so a paused player still holds no flow (#310) and a parked consumer cannot be driven into a timer-paced reconnect loop (#307). Detection alone would not have fixed what the reporter measured. The frontier refill fired only for PLANNED ends, so a faulted generation was replaced only once the window hit empty: the reader spent its whole read-ahead before asking for a replacement, and playback rejoined the clock with a burst (+17 MB in one interval, 389 dropped frames). Any reason for having no flow now refills at low water, with the reason selecting the policy. A fault pays the failure ladder (status accounting, pin invalidation, bounded give-up) with its backoff as a next-attempt timestamp rather than a sleep, because sleeping on the demux thread would starve the demuxer of the very read-ahead the early replacement protects. It emits no `.reconnecting` phase while the window still serves, and it never fails the read; termination stays with the empty-window ladder. Tests: a loopback origin that stops writing mid-body without a FIN, which is the reader-observable shape of the field case. Both parts verified by falsification (watchdog disabled: the dead flow stays installed; runway refill disabled: the replacement is asked for with 0 KB of read-ahead left). Real-media A/B through a rate-limited, delayed origin: identical request sequence to main on a 365 MB moov-at-end MP4, zero watchdog lines. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
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.
Addresses #309. Two defects, and only the first one is in the report.
Detection: the watchdog only ticked inside a waiting read()
connStallTimeoutwas evaluated in exactly one place, the read loop's forward wait (AVIOReader.swift:1351before this change), so a transport that died while the sliding window could still serve reads was noticed only once a consumer happened to block on it. The transport does not cover that gap either: the persistent request is issued withrequest.timeoutInterval = 0on purpose, so the reader is the only detector there is.A delivery-gap watchdog now ends a generation that has an installed transfer and no delivery for
connStallTimeout, whether or not a read is waiting on it. Same threshold, same action as the read-side wait; what is removed is the accidental exemption for a well-buffered reader. One pending closure per generation on a shared serial queue: it either ends the connection or re-arms itself for the remaining gap, so a healthy transfer costs one timestamp comparison perconnStallTimeoutand an ended generation arms nothing.It only ENDS, it never reconnects. Opening connections stays with the read thread, so a paused player still holds no flow (the #310 invariant) and a parked consumer cannot be turned into a timer-paced reconnect loop (the #307 failure mode). The gap is named in a release-visible line, which is what the field case had no witness for.
The threshold stays 20 s and stays out of
LoadOptions: #272 measured that a shorter one is worse under CPU starvation, and that conclusion is unchanged. The new hook is a test clock only.Recovery: a faulted connection waited for an EMPTY window
This is where the measured harm was, and detection alone would not have moved it. The frontier refill fired only for PLANNED ends (
connEndedAtRangeEnd || connEndedByBackpressure); a generation that ended in fault was replaced only onceavailable == 0. The reader therefore spent its entire read-ahead before asking for a replacement, which is why playback rejoined the clock with a burst (+17 MB in one interval, 389 dropped frames in the report) rather than simply carrying on.The refill condition is now "no flow installed and the consumer has drawn down to low water", for every reason there is no flow. The reason still selects the policy: a planned end costs nothing, a fault pays the failure ladder (status accounting, pin invalidation, bounded give-up), with two deliberate differences from the empty-window ladder:
.reconnectingphase while the window serves: playback is uninterrupted there, and a phase flapping per read would describe bookkeeping rather than what the viewer sees.The trade this makes, stated plainly
An origin that pauses for more than
connStallTimeoutmid-body while its socket stays alive now loses that connection, where a well-buffered reader used to ride the pause out. That is already the engine's policy whenever the window is thin (which is the common case on a slow link), so this makes it consistent rather than new; and for a live source a 20 s delivery gap means the content is gone from that connection anyway. The replacement is asked for at low water rather than immediately, so a hiccup shorter than the remaining runway costs one range request and no visible interruption.Verification
Issue309SilentTransportDeathTests, against a loopback origin that stops writing mid-body without closing the socket and without a FIN, which is the reader-observable shape of the field case (ThrottledOriginServer.Directive.serveThenGoSilent). Four cases: a flow that dies mid-window is ended with no read blocking on it; a generation that never sees a first byte is ended too; the replacement is requested while read-ahead remains; and a backpressure-parked reader is NOT treated as a dead flow.Falsification, both parts separately: with the watchdog disarmed the dead flow stays installed after 6x the threshold; with the runway refill disabled the replacement is asked for with 0 KB of read-ahead left. The regression case passes in both arms.
Full suite: 1548 tests, all passing.
Real media,
aetherctl play --seconds 40on a 365 MB moov-at-end MP4 through a Range-logging origin paced at 4 MB/s with a 60 ms header delay: identical request sequence and cadence tomain(six requests, same offsets, ~9 s apart), zero watchdog lines, zero faults.Measured, with a positive control, that the transport really does not cover this: against an
origin that answers 206 headers and then goes silent, a request with
timeoutInterval = 5fails
-1001after 5.0 s, whiletimeoutInterval = 0(what the persistent path uses) wasstill running after 100 s even though the session config carries the default 60 s
timeoutIntervalForRequest. So a per-request 0 disables the idle timer and overrides thesession value, and the pre-fix exposure was unbounded rather than capped at 60 s.
The runway assertion is read from the ORIGIN's thread at the moment it receives the replacement request, not from a wall clock: a loopback origin answers in microseconds, so timing could not express it.
🤖 Generated with Claude Code