Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive request timeouts #837

Merged
merged 10 commits into from
Mar 1, 2024
Prev Previous commit
Next Next commit
Cancel ticker if there is no response body
  • Loading branch information
pietern committed Feb 29, 2024
commit c4add3af7f4d92e1ca2cd4456fa2673cfc11df6e
5 changes: 5 additions & 0 deletions httpclient/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ func (c *ApiClient) attempt(
// If there is a response body, wrap it to extend the request timeout while it is being read.
if response != nil && response.Body != nil {
response.Body = tickingReadCloser(ticker, response.Body)
} else {
// If there is no response body, the request has completed and there
// is no need to extend the timeout. Cancel the context to clean up
// the underlying goroutine.
ticker.Cancel()
}

// By this point, the request body has certainly been consumed.
Expand Down
Loading