perf(download): cancel context on first worker failure to stop remaining workers #140

Closed
opened 2026-07-13 18:08:01 +00:00 by the.auditor · 1 comment
Owner

internal/downloader/download.go:194-199 — When Download() receives the first chunk error from results, it closes the file and returns. Other workers continue running until they exhaust retries, wasting time and bandwidth.

Suggestion: use context.WithCancel to cancel all workers on first error:

ctx, cancel := context.WithCancel(ctx)
defer cancel()

// ... in the results loop:
for res := range results {
    if res.Err != nil {
        cancel()
        _ = file.Close()
        return ...
    }
}

Discovered during review of PR #137.

`internal/downloader/download.go:194-199` — When `Download()` receives the first chunk error from `results`, it closes the file and returns. Other workers continue running until they exhaust retries, wasting time and bandwidth. Suggestion: use `context.WithCancel` to cancel all workers on first error: ```go ctx, cancel := context.WithCancel(ctx) defer cancel() // ... in the results loop: for res := range results { if res.Err != nil { cancel() _ = file.Close() return ... } } ``` Discovered during review of PR #137.
Owner

Closing — implemented in PR #165. Context is cancelled on first worker failure, stopping remaining in-flight workers immediately.

Closing — implemented in PR #[165](https://git.lan.thwap.org/thwap/pget/pulls/165). Context is cancelled on first worker failure, stopping remaining in-flight workers immediately.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/pget#140
No description provided.