-
-
Notifications
You must be signed in to change notification settings - Fork 844
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
Add retries #778
Add retries #778
Conversation
Yes, definitely going to split this into a more manageable first chunk of work that can actually be considered for merging… 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent, thanks @florimondmanca!
I left some suggestions, questions and implementation comments.
I didn't take part of the discussions leading to this PR so apologies if this was brought up before, but I feel adding built-in retries to httpx, while immediately useful, might be a source of pain for maintainers as users want more customization options, particularly when retrying
and its successor tenacity
offer so much in those terms. I can forsee having to push back on these or extend our implementation into a not-so-generic version of tenacity
.
That's my 2c anyway, it's a really neat implementation 💯
@yeraydiazdiaz In my opinion, I think that httpx could provide a basic retry functionality out of the box (including respecting the As is, I still like the progress on this so far. Definitely on board with a minimal implementation, and leaving it at that. Since other retry libraries do exist, we don't have to be too comprehensive with this one, even perhaps leaving off the composition (though I think that's quite neat and I haven't seen it before). Go go @florimondmanca! 👍 |
Thanks for this first round of reviews! I'm preparing a PR with just the |
Also worth mentioning that a middleware API such as the one outlined in #783 would 100% make it possible to provide |
Is it necessary to do multiple PRs? Why not modify this one? |
Closing in favor of #784.
Allows keeping older PRs for future reference, and not have the cruft of comments/feedback from changes that were largely overridden. :-) |
I slept some more on #765, and I think I've come up with something quite nice.
Main changes compared to #765:
Schedule
API. Just abackoff_factor
know on the retries config class.RetryableError
base class — which of our exceptions are retryable is hard-coded in the default behavior..retry_flow()
isn't really useful in itself, because extending a retry flow (even by copy-pasting our code) really isn't easy, due to many generator gotchas to watch for. So this PR implements some extension capability, mainly via theRetryLimits
interface and being able to pass . I guess in an incremental approach we could restrict this PR toretries=<int>
andretries=Retries(<int>[, backoff_factor=<float>])
, and move the extension mechanism to a separate/future PR. I'm putting everything in here first to get some more feedback on the direction.Things still to do:
retries
.retries
.Notes to reviewers:
HTTPX_LOG_LEVEL=debug python example.py
without starting the server, to try the behavior on connection failures.uvicorn example:app
RetryOnStatusCodes
.