Repository navigation
fix: give up on servers that take the connection and never answer - #638
Conversation
Engines wait for an answer as long as it takes, and only transfers ran under the stall watchdog. A server that accepted the connection and never answered (a broken proxy or middlebox) held `ketch <url>` at "Getting ready..." forever: no retry, no failure, and an app's task stayed Starting. The requests made before a transfer now run under the download's TransferWatchdog (DownloadConfig.idleTimeoutMs, 60 s by default), in resolve too: HTTP's HEAD and probe, HLS and DASH manifests and segment indexes, the Metalink document and its mirrors' HEADs, and WebDAV's PROPFIND and probe. One that gets no answer fails as a stalled transfer does, with a retryable network error. The media integration test runs its real-server body off the test scheduler, whose virtual time fired the watchdog while requests were on the wire.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 992bf68948
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
HttpEngine.request reads a success's body itself, up to 1 MiB, without handing chunks to its caller, so under the watchdog a long PROPFIND answer still arriving, as a server taking PROPFIND for GET sends, was cancelled as idle rather than reaching the too-long fallback. TransferWatchdog.watch now runs its block with a TransferProgress context element holding its monitor, and KtorHttpEngine reports the bytes of the bodies it reads itself to it. Bytes delivered through callbacks stay the caller's to report, so nothing is counted twice.
Problem
Engines wait for an answer as long as it takes, and only transfers ran under the stall watchdog (
TransferWatchdog). If a server accepts the TCP connection and never answers, as a broken proxy or middlebox does:ketch http://…sits at[Starting] Getting ready...forever. I tested 200 s; it made one connection, with no retry and no failure.The same applies to everything requested before a transfer starts: HLS/DASH manifests, Metalink documents and WebDAV
PROPFINDs.Fix
The requests made before a transfer now run under the download's
TransferWatchdog. This usesDownloadConfig.idleTimeoutMs, 60 s by default (0 turns it off), plusminSpeed. Inresolvethe watchdog comes fromTransferWatchdog.of(config); indownloadit'scontext.watchdog. Covered:HEADand the ranged-GET probe (RangeSupportDetector). A silentHEADfalls back to the probe, like any other network failure.MediaDownloadHelper.fetchManifest,fetchRange).HEADs; a silent mirror is passed over.PROPFINDand the probe.A request that gets no answer fails the way a stalled transfer does: a retryable
KetchError.Networkcaused by aTransferStalledException.DownloadExecutionthen retries it and finally reports it.MediaDownloadIntegrationTestnow runs its real-server bodies onDispatchers.IO. UnderrunTest, the virtual clock skipped the watchdog's delays while requests were on the wire and reported a stall at once.TorrentTlsTestalready does this.Tests
RangeSupportDetectorTest:HEADnor the probe fails after both waited the timeout (60 s on virtual time).HEADfalls back to a probe that answers.HlsDownloadSourceTest.resolve_serverNeverSendingThePlaylist_failsAsAStall.core,hls,dash,metalink,webdav,ktor,serverandclipass.