The Timeout Math That Breaks Your Retry Loop
Your client has a 10-second timeout and three retries. You expect a worst case of roughly 30 seconds. Your caller, who put a 30-second deadline on the whole operation, disagrees — and finds out when their request dies anyway. The problem is that most retry loops treat timeouts as per-attempt values with no global budget. By the end of this article you'll be able to compute a real worst-case…
The article discusses the issue of per-attempt timeouts in retry loops and how they can lead to exceeding a caller's deadline. It explains that a timeout on a single HTTP attempt only bounds one connection and does not take into account the total time of the operation. The author introduces a method to budget the deadline across attempts, starting from the total time the caller is willing to spend and dividing it among the attempts.
This approach ensures that the timeout for each attempt is capped by the remaining budget, preventing any single attempt from outliving the caller's deadline. The article also emphasizes the importance of propagating the deadline down the call stack, so that each layer of the system knows the remaining time for its operations.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.