🧱 Chunk is a download manager for slow and unstable servers

Retry counting is off-by-one and inconsistent; 404s are retried like transient errors #12

Open cuducos.me
Open opened by cuducos.me

Problem

Retry counts are inconsistent between the two retry loops and do not match the documented contract:

  • downloadChunk does n++ then checks n >= MaxRetries (downloader.go:290-291): MaxRetries = 3 yields exactly 3 attempts (2 retries).
  • getDownloadSize request-error path uses n > MaxRetries (downloader.go:226-227): 4 attempts for the same setting.

Additionally, any non-200 status — including permanent ones like 404 — goes through the same retry path (downloader.go:240-250), so permanent errors burn WaitRetry × N for nothing.

Reproduction (verified)

  • MaxRetries = 3 → exactly 3 GET attempts against a 500.
  • The same 3 attempts against a 404.

Flag help and README say "maximum number of retries", so users expect MaxRetries + 1 attempts.

Suggested fix

Unify the counting (n >= MaxRetries or n > MaxRetries everywhere) and skip retries for permanent status codes (404, 4xx non-retryable).

Sign up or Sign in to add to the discussion.