-
Notifications
You must be signed in to change notification settings - Fork 129
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
retry
: handle unexpected float delays
#464
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR. Could you add a unit test? |
Could you double check if fractions are allowed by RFC 9110? If not we shouldn’t change this parsing, perhaps the issue is somewhere else. |
I think it's a bit of a grey area - RFC 9110 dictates that it should be a non-negative integer, but APIs / rate limiters often pass back fractional values because they're just doing a raw date diff. Maybe a better way to handle this is to continue parsing as an integer, but handle the case where a fractional part is present by just adding an extra second? It would be nice to handle this at the library level instead of having to add boilerplate for handling errors downstream. |
I made some updates based on the approach above and added some test coverage for |
retry_delay_in_ms
: handle unexpected float delays
@wojtekmach I've made the suggested changes and added tests. Would you have time to review this approach of handling fractional delays by rounding up? Let me know if I should close this PR or if you'd like additional changes. |
Apologies for delay. My bad. I think your solution is pragmatic however to be completely honest I'm not keen on accommodating broken servers that do not follow the spec. Looks like curl and Python requests ignore such invalid value for what it's worth. We have some escape hatches in https://hexdocs.pm/req/Req.Steps.html#retry/1. Would any of these work for you? Using If the current |
retry_delay_in_ms
: handle unexpected float delaysretry
: handle unexpected float delays
Thanks for the response. I believe I should be able to handle it using a custom retry function. In the meantime, I'll also take a look into those related issues! |
When retry delays were introduced in #226 it was implied that the retry delay would be greater than or equal to 1s. In situations where retry delays are either passed back as floats and/or less than 1s, it would be nice to use full precision since we're converting to milliseconds anyway.
This specifically fixes a problem in my case where an API is consistently handing back retries that are less than 1s, i.e. 0.314s.