Repository navigation
fix(engine): retry a connection that stops sending - #1
Conversation
troke12
left a comment
There was a problem hiding this comment.
Looks correct overall (timer/goroutine cleanup and pause semantics are good). Two requests:
- The 30 s limit also bounds the wait for response headers. Servers that build the file before replying (on-the-fly archive/export endpoints) will now fail after 8 retries, where they work on
main. Please use a separate, longer header timeout (or make it a setting). TestStalledConnectionRetriesFromLastBytenever asserts that the retry asked forbytes=4096-; it would still pass if the chunk restarted from 0.
Minor: one goroutine + timer per 64 KiB read is on the hottest path; a single time.AfterFunc(idle, body.Close) reset after each read would be cheaper. Inspect (probe) is still unbounded.
Note for the whole set (#1–#11): thanks a lot for these! They are all branched from 5350f79 independently, so every pair conflicts on CHANGELOG.md and most on download.go. main has also moved (e830f5d adds a stream downloader that touches download.go). Could you rebase onto current main and stack them in this order: #1 → #2 → #10 → #8 → #5/#6/#7/#11? #2, #3 and #10 each add their own pass loop / transferCancel in Start; one shared design would be much easier to merge.
Brings the eleven engine changes (troke12/odm troke12#1-troke12#11) onto upstream v0.3.0-rc1. Conflicts in CHANGELOG.md and internal/engine/download.go keep both sides: the stream fields and the d.Stream branch from upstream run before the engine's pass loop, and State saves both the validators and the stream job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57e7ff5 to
b0783bb
Compare
|
Rebased onto current |
A worker blocked in the response body when a server accepted the range and then sent no further bytes. Close that body after 30 seconds without a read and retry the chunk from the last written offset. Pause still cancels the whole transfer, and the other connections are left running.
The stall limit now covers the wait until response headers arrive. It is stopped once they do, so a long body is still limited only by idle reads. A pause during that wait is not a stall.
Review changes on top of the previous two commits: - The wait for response headers is bounded by DefaultHeaderTimeout (5 minutes) instead of the 30 s stall limit. A server that builds the file before answering (an on-the-fly archive or export) sends nothing until it is done; with the stall limit it failed after 8 retries, where it works on main. TestSlowHeadersWithinHeaderLimit covers it. - The body's idle limit is one time.AfterFunc per connection, armed only around each Read, instead of a goroutine and a timer per 64 KiB read. Time spent in the speed limiter between reads no longer counts as idle. - TestStalledConnectionRetriesFromLastByte asserts the retry asks for bytes=4096-, so it fails if the chunk restarted from 0. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
b0783bb to
4a48126
Compare
Review changes on top of the previous commit: - TestProbeFirstByteSingleChunk covers the regression the review found: a server answering 206 to bytes=0-0 but 200 to a range over the whole file, with one connection or a file too small to split. With troke12#10 on main the whole-file 200 is kept, so it completes in one request. - Test servers no longer tell the probe by its open-ended range, which bytes=0-0 broke (troke12#1, troke12#7 and troke12#10 fixtures): isProbe and probeRange in engine_test.go, and testRange reports the probe as not explicit. - The PR's test helper is renamed testWholeSpan (wholeFileRange is now a production function) and the test moves to probe_byte_test.go, as probe_test.go exists on main. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
Review changes on top of the previous commit: - TestProbeFirstByteSingleChunk covers the regression the review found: a server answering 206 to bytes=0-0 but 200 to a range over the whole file, with one connection or a file too small to split. With #10 on main the whole-file 200 is kept, so it completes in one request. - Test servers no longer tell the probe by its open-ended range, which bytes=0-0 broke (#1, #7 and #10 fixtures): isProbe and probeRange in engine_test.go, and testRange reports the probe as not explicit. - The PR's test helper is renamed testWholeSpan (wholeFileRange is now a production function) and the test moves to probe_byte_test.go, as probe_test.go exists on main. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
Summary
A connection that accepts a range and then sends no further bytes used to block its worker inside
Body.Read. The wait for response headers could block the same way, insideClient.Do. Neither reached the retry loop, so the transfer sat there until the whole download was paused.Both waits are now bounded. A connection that goes quiet mid-body is closed after 30 seconds and its chunk is retried from the last byte already written. A connection still waiting for headers gets 5 minutes, because some servers build the file (an archive, an export) before they answer. The other connections of the same file keep going. Pause still cancels the whole transfer and does not count as a stall.
Behavior
DefaultStallTimeout(30 s). It is onetime.AfterFuncper connection, armed only around eachRead, so time spent in the speed limiter between reads is not counted as a stall.DefaultHeaderTimeout(5 min). It is stopped once the headers arrive, so a long transfer is not cut off.errStalled. The existing retry loop (up toMaxRetries, with the same backoff) requests the chunk again fromchunk.Next().d.guardedClient()(the local-network guard onmain), notd.client.Commits
be198b8,a8da922(Ryan Bagas): the original change, rebased onto currentmain. The conflict resolution routesexchangethroughguardedClient().b0783bb: review changes. Adds the separate header limit, replaces the per-read goroutine+timer with oneAfterFunc, and asserts the retry Range.Not changed
Inspect(the probe) still has no header limit. Left for a follow-up.Test plan
go test ./...andgo test -race ./internal/engineTestStalledConnectionRetriesFromLastByte: after 4 KiB and a stall, the retry asks forbytes=4096-…and the file matches the source.TestHeaderStallRetries: no headers within the header limit retries the chunk.TestSlowHeadersWithinHeaderLimit: headers slower than the stall limit but within the header limit succeed on the first transfer. This test fails if the header wait reuses the stall limit.TestPauseDuringHeaderWaitIsPaused✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)