Open ThomasJanUta opened 2 years ago
Agreed this seems undesirable.
Since max
is passed in, it feels like the sleep time should be: min(serverRetryAfter, max)
Wouldn't a better fix to pass in a context, so that it can be controlled by the requester via context.WithTimeout
or similar. That way we can just cancel it at any point anyway. This gives more flexibility, the only downside is that it's a breaking change.
If a server sets the waiting time for the status "429 TooManyRequests" to 24 hours or even more, the client will hang for this amount of time. This scenario is not uncommon for servers that implement drastic rate limits.
This line in the backoff function
allows to wait if the server currently does not accept requests.
You can set a timeout for the http.client:
client.HTTPClient.Timeout = time.Duration(timeout) * time.Second
but it does not apply to the DefaultBackoff function.Is this the desired default behavior?
This is the fix in my code I use. It currently still retries but at least it's not hanging:
Is there a better fix? I can offer a pull requests if wanted.