Skip to content

feat(engine): open connections one at a time - #11

Merged
troke12 merged 2 commits into
troke12:mainfrom
rigaz29:engine-ramp-connections
Oct 19, 2026
Merged

troke12 merged 2 commits into
troke12:mainfrom
rigaz29:engine-ramp-connections

Conversation

@rigaz29

@rigaz29 rigaz29 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A segmented download used to open all N connections at once. Now it opens them one at a time: the first one immediately, and each next one once file bytes arrive on any connection after the last one opened, up to the configured limit.

  • A server that refuses or never answers (503, a queue, an edge still warming up) sends no bytes, so it is not asked on more connections.
  • One stalled connection does not keep the rest closed while others are bringing bytes in. The review found that with the original "every opened connection has bytes" rule, this froze the ramp for good.
  • A worker error does not stop the ramp; the run may still complete.
  • One-connection mode (fix(engine): continue on one connection when a range is ignored #10) and servers without ranges open a single connection.

How

ramp runs as its own goroutine in the pass loop and holds a count on the pass's WaitGroup while it may add workers, so Wait cannot return early. Writes signal it under the same lock that updates chunk progress (rampArmed/rampReady). It ends when every connection is open, the pass ends (pause, changed file, ignored range), or nothing is left to hand out (hasWork).

Commits

  • fac05d8 (Ryan Bagas): the original change, ported onto the pass loop on main. Its test fails at this commit because the bytes=0-0 probe counts as a transfer.
  • 4e82d00: review changes. Any-connection bytes gate, ramp goroutine, no stop on worker error, tests rewritten without sleeps.

Test plan

  • go test ./..., go test -race ./internal/engine, ramp tests ×5 with -race
  • TestConnectionsRampAfterFileBytes: one connection until bytes arrive, then all 4. It counts opened connections, not requests.
  • TestRampPassesAStalledConnection: connection 2 hangs before headers and connection 3 still opens. Fails when the ramp only re-arms for the first connection.
  • TestRefusedResponseDoesNotOpenMoreConnections: a server refusing every transfer gets only one connection while it retries.
  • TestRampRespectsOneConnectionMode: fails if the pass ignores alone.

✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)

@troke12 troke12 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

WaitGroup/lifecycle looks correct. Changes I'd like:

  • One slow connection freezes the ramp: connection k+1 only opens after k gets its first byte. If k never does (cold edge, per-IP queueing, slow headers), the remaining connections never open, where main would have opened all N. Please add a timeout, or gate on "any newly opened connection received bytes".
  • After any worker error sets StatusError, ramping stops for good even if the run can still complete.
  • Should respect #10's single-connection mode (alone).
  • Tests use a 150 ms Sleep to prove something didn't happen; please synchronise with channels/counters. The arrivals channel (cap 4) blocks the handler on any extra request — and #8's 0-0 probe will be counted by explicitRange.

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.

rigaz29 added a commit to rigaz29/odm that referenced this pull request Oct 15, 2026
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>
rigaz29 and others added 2 commits October 19, 2026 10:44
The next connection starts after every connection already open has
stored file bytes, up to the configured limit.
Review changes on top of the previous commit, which ports troke12#11 onto the
pass loop on main:

- The next connection opens once file bytes arrive on any connection
  after the last one opened, not once every opened connection has had
  bytes. A connection that never got its first byte froze the ramp for
  good, where main opened all N; now the others keep it going
  (TestRampPassesAStalledConnection). Without a timer, a server that
  refuses every transfer is still not asked on more connections.
- ramp runs as its own goroutine holding a count on the pass's
  WaitGroup, and ends when every connection is open, the pass ends, or
  nothing is left to hand out (hasWork). A worker error no longer stops
  it: the run may still complete.
- One-connection mode (troke12#10) and !RangeOK open a single connection.
- Tests use no sleeps to show something did not happen: only file bytes
  open a connection, so while bytes are held back none can. They count
  opened connections (rampOpened), not requests, and tell the probe by
  bytes=0-0 (isProbe).

✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
@troke12
troke12 force-pushed the engine-ramp-connections branch from ffd4737 to 4e82d00 Compare October 19, 2026 03:49
@troke12

troke12 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Rebased onto current main and applied the review: the next connection now opens on file bytes from any connection since the last one opened, so a stalled connection no longer freezes the ramp, while a server refusing everything still gets one connection. A worker error no longer stops ramping, #10's one-connection mode is respected, and the tests use no sleeps (they count opened connections and recognise the 0-0 probe). Your commit is kept with you as author (ported onto the pass loop); the review changes are a separate commit on top. Thanks!

@troke12
troke12 merged commit 7f7a89a into troke12:main Oct 19, 2026
5 checks passed
@rigaz29
rigaz29 deleted the engine-ramp-connections branch October 19, 2026 05:01
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.

2 participants