Skip to content

Replace sleep(2) in BazaRb#download with exponential backoff #372

Description

@VasilevNStas

Replace sleep(2) in BazaRb#download with exponential backoff

Severity: LOW

Location

lib/baza-rb.rb:815-817:

if blanks.include?(resp.code)  # blanks = [302, 204]
  sleep(2)
  next
end

Problem

sleep(2) is hardcoded. If the server needs 5 seconds to prepare the next chunk, the client makes 3 useless requests. If 1 second — the client waits an extra second. No retry limit — infinite loop on persistent server issues.

History

sleep(2) was added in #120 (closed, "let's sleep a bit after 204"). It was a correct fix at the time. This proposal improves it.

Recommended fix

max_retries = 10
wait = 1

(1..max_retries).each do |attempt|
  # ... request ...
  break unless blanks.include?(resp.code)
  sleep(wait)
  wait = [wait * 2, 60].min
end

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions