question 476 Observability & Operations · medium
The retry that hides failures
Two complaints about fetch_with_retry: a request with a malformed repository name takes seven seconds of waiting before anything happens, and when the star service is completely down, callers get None and show "0 stars" instead of an error. Fix it: retry only TimeoutError, wait 2**n seconds through sleep between tries, and re-raise when the tries run out.
Function
fetch_with_retry(fetch, repo, sleep, attempts=4)Retryonly
TimeoutError; any other exception is raised at once, without waitingWaits
sleep(2**n) before the next try (1, 2, 4 …)Returns
fetch(repo)'s result; raises the last TimeoutError after attempts tries