Skip to content

feat(engine): continue on one connection when ranges disagree - #3

Closed
rigaz29 wants to merge 1 commit into
troke12:mainfrom
rigaz29:engine-conflict-fallback
Closed

rigaz29 wants to merge 1 commit into
troke12:mainfrom
rigaz29:engine-conflict-fallback

Conversation

@rigaz29

@rigaz29 rigaz29 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Summary

When two connections receive different bytes for the same offset, ODM stops the extra connections and finishes the file on one. If that copy disagrees as well, the partial file is discarded and the download starts again from the first byte, still on one connection.

Behavior

  • A chunk that begins after another chunk re-reads 64 bytes of the earlier chunk and compares the two copies.
  • A mismatch cancels the other connections, keeps the bytes before the mismatch, and continues with one connection.
  • A second mismatch deletes the partial file and downloads it again from byte 0 on one connection. A further mismatch fails the download.
  • A resume after this fallback stays on one connection (single in the saved state). Consistent ranges still use every configured connection.

Test plan

  • go test ./... (65 tests)
  • Pause a multi-connection download and resume it; the file still matches
  • A large file from an ordinary server still uses more than one connection

When two connections return different bytes for the same offset, keep the matching prefix and finish on one connection. If that copy disagrees too, discard the partial file and start again from the first byte.

@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.

Thanks for the effort here, but I don't think we'll take this one:

  • The 64-byte boundary witnesses live only in memory and are cleared on pause, so a boundary that wasn't verified before a pause is never compared after resume — the inconsistent-backend case this targets can still slip through silently.
  • d.file.ReadAt runs under d.mu, which the UI also takes.
  • restarted resets on every Start, so a server that always disagrees loops forever across pause/resume.
  • Detection only samples chunk boundaries; the README wording overstates it.

The main real-world case (file replaced mid-download) is better covered by If-Range (#2), and the pass-loop machinery overlaps with #10. Happy to reconsider if there's a concrete server that needs it.


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.

@troke12

troke12 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Closing per the review above: the boundary witnesses are lost on pause and the restart flag resets each Start (so a disagreeing server can loop), and the main real-world case — a file replaced mid-download — is being covered by If-Range in #2, with the one-connection fallback from #10. Thanks a lot for the work; happy to reopen if a concrete server turns up that needs this.

@troke12 troke12 closed this Oct 19, 2026
@rigaz29
rigaz29 deleted the engine-conflict-fallback 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