Skip to content

fix: give up on servers that take the connection and never answer - #638

Merged
linroid merged 2 commits into
mainfrom
fix/http-probe-timeout
Oct 23, 2026
Merged

linroid merged 2 commits into
mainfrom
fix/http-probe-timeout

Conversation

@linroid

@linroid linroid commented Oct 23, 2026

Copy link
Copy Markdown
Owner

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.
  • In the apps, the task stays "Starting" forever.

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 uses DownloadConfig.idleTimeoutMs, 60 s by default (0 turns it off), plus minSpeed. In resolve the watchdog comes from TransferWatchdog.of(config); in download it's context.watchdog. Covered:

  • HTTP: HEAD and the ranged-GET probe (RangeSupportDetector). A silent HEAD falls back to the probe, like any other network failure.
  • HLS and DASH: manifests and DASH segment indexes (MediaDownloadHelper.fetchManifest, fetchRange).
  • Metalink: the document, plus the mirrors' HEADs; a silent mirror is passed over.
  • WebDAV: PROPFIND and the probe.

A request that gets no answer fails the way a stalled transfer does: a retryable KetchError.Network caused by a TransferStalledException. DownloadExecution then retries it and finally reports it.

MediaDownloadIntegrationTest now runs its real-server bodies on Dispatchers.IO. Under runTest, the virtual clock skipped the watchdog's delays while requests were on the wire and reported a stall at once. TorrentTlsTest already does this.

Tests

  • RangeSupportDetectorTest:
    • A server answering neither HEAD nor the probe fails after both waited the timeout (60 s on virtual time).
    • A silent HEAD falls back to a probe that answers.
  • HlsDownloadSourceTest.resolve_serverNeverSendingThePlaylist_failsAsAStall.
  • The JVM tests of core, hls, dash, metalink, webdav, ktor, server and cli pass.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T19:44:07.510159Z 992bf68 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 202 files  + 1   2 230 suites  +1   57m 16s ⏱️ -23s
15 400 tests +13  15 132 ✅ +13  268 💤 ±0  0 ❌ ±0 
18 767 runs  +13  18 499 ✅ +13  268 💤 ±0  0 ❌ ±0 

Results for commit 86b0ad0. ± Comparison against base commit 9ad8952.

@linroid
linroid merged commit bafe7ff into main Oct 23, 2026
14 checks passed
@linroid
linroid deleted the fix/http-probe-timeout branch October 23, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant