From 3ffbf6a3b20019b92f846775930fbfca2e85a05b Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sun, 10 May 2026 14:03:21 -0400 Subject: [PATCH] Don't start backoff timer if it would exceed context deadline If the backoff wait time would push past the context deadline, there's no point starting the timer at all. We'd just block until the deadline fires and get context.DeadlineExceeded anyway. Instead, check upfront and return immediately so callers get the error without the unnecessary wait. --- client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client.go b/client.go index 3a22b99..a28b093 100644 --- a/client.go +++ b/client.go @@ -781,6 +781,10 @@ func (c *Client) Do(req *Request) (*http.Response, error) { v.Printf("[DEBUG] %s: retrying in %s (%d left)", desc, wait, remain) } } + if deadline, ok := req.Context().Deadline(); ok && time.Now().Add(wait).After(deadline) { + c.HTTPClient.CloseIdleConnections() + return nil, req.Context().Err() + } timer := time.NewTimer(wait) select { case <-req.Context().Done():