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

Honour "Retry-After" header value only if its less than or equal to RetryWaitMax in default retry strategy #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Hemanthk1099
Copy link

#247

Currently the DefaultBackoff in function has a logical flaw when handling the Retry-After header. If the server provides an unreasonably high value in the Retry-After header, the function respects it without enforcing the RetryWaitMax limit set for the httpClient. This can lead to indefinite wait times or blocking behaviour.

This change will make sure that "Retry-After" header value is honoured only if its less than or equal to RetryWaitMax in default retry strategy.

@Hemanthk1099 Hemanthk1099 requested review from a team as code owners December 23, 2024 22:48
Copy link

hashicorp-cla-app bot commented Dec 23, 2024

CLA assistant check
All committers have signed the CLA.

@julianmaze
Copy link

Can we get a PR review on this? This is a much-needed addition by @Hemanthk1099. I too am experiencing seemingly stuck HTTP calls when a 429 Retry-After value is higher than RetryWaitMax.

@davidcollom
Copy link

davidcollom commented Mar 31, 2025

I too have this issue with calls to the Docker Container Registry...

INFO[0036] [DEBUG] GET https://registry.hub.docker.com/v2/repositories/XXXXX/XXXXX/tags?page_size=100 (status: 429): retrying in 484289h20m8s (10 left)  client=docker component=clientz

🙈

I did make a work around by implementing the following:

func HTTPBackOff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
	sleep := retryablehttp.DefaultBackoff(min, max, attemptNum, resp)
	if sleep <= max {
		return sleep
	}

	return 0
}

// Then Setup the client..
retryclient := retryablehttp.NewClient()
retryclient.HTTPClient.Timeout = 10 * time.Second
retryclient.RetryMax = 10
retryclient.RetryWaitMax = 10 * time.Minute
retryclient.RetryWaitMin = 1 * time.Second
retryclient.Backoff = HTTPBackOff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants