Skip to content

fix(chunk_tracker): take a piece out of the queue when it becomes have - #655

Open
zond wants to merge 1 commit into
ikatson:mainfrom
zond:chunk-tracker-dequeue-on-have
Open

zond wants to merge 1 commit into
ikatson:mainfrom
zond:chunk-tracker-dequeue-on-have

Conversation

@zond

@zond zond commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Between its last chunk arriving and its hash passing, a piece is neither queued, in-flight nor have. update_only_files() re-selecting its file in that window sees "selected and not have" and queues it, and when the hash then passes the piece is have AND queued: the next peer to ask is handed a piece we have, downloads it again over the same bytes, and the completion is counted twice.

mark_piece_downloaded() now clears the queue bit alongside setting have, which restores queued ⊆ !have at the one place it could break. The test walks exactly that interleaving.

Generated by my Claude Fable.

Here my agent has solved it in a way that I'm not fully 100% I agree with - but it is a very simple solution - just force set queued to false after it's marked as downloaded should make all newly downloaded pieces never be queued. But maybe there's a better way more in line with project style that I don't see?

Between its last chunk arriving and its hash passing, a piece is neither
queued, in-flight nor have. update_only_files() re-selecting its file in
that window sees "selected and not have" and queues it, and when the
hash then passes the piece is have AND queued: the next peer to ask is
handed a piece we have, downloads it again over the same bytes, and the
completion is counted twice.

mark_piece_downloaded() now clears the queue bit alongside setting have,
which restores queued ⊆ !have at the one place it could break. The test
walks exactly that interleaving.
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