🧱 Chunk is a download manager for slow and unstable servers

Status stream is non-monotonic and consumers can deadlock on IsFinished() #8

Open cuducos.me
Open opened by cuducos.me

Problem

The status stream is not monotonic: already-downloaded (skipped) chunks emit statuses with stale counters (downloader.go:364-375) after later chunks have already reported higher values, and chunk goroutines complete out of order (an error status can arrive before a success).

Impact

A consumer that stops draining at the first IsFinished() == true status blocks: more statuses are still queued on the channel, the producers block forever on ch <- s, and the WaitGroup never completes.

Suggested fix

Make the status stream monotonic (track the highest value reported per file) and/or document that consumers must drain the channel until it is closed.

Partially addressed by 97e2f491 — but deadlock is still a possibility I guess.

Sign up or Sign in to add to the discussion.