-
Notifications
You must be signed in to change notification settings - Fork 108
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 connect retries #221
Add connect retries #221
Conversation
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.
I like this as a most basic (but still useful) implementation of retries 🎉
Only question is whether the parameter should be retries
or connect_retries
? Not sure if that discussion has already been had somewhere?
Sorry for the question. You added the retries mechanism only for connection establishing yes? It's talking about the possibility, if we may be introducing some sort of After that we can carefully handle retry for, e.g. "HTTP POST" requests (allow retries for connect, but do not allow after that) What do you think about that? PS reference link : urllib3 retry doc (they also separate the retries types) |
I think we've had it already on the HTTPX repo. TLDR was "let's use @cdeler Yes only connection for now, as an absolute minimum viable feature and implementation. As I explained above we can easily expand later based on feedback and proven needs. There's a lot of background for why this minimum scope was chosen in: encode/httpx#1141 and encode/httpx#1196. |
Co-authored-by: Jamie Hewland <[email protected]>
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.
I'm happy with this 😄
Fantastic, lovely piece of work! And yup, once we've had a good look at encode/httpx#1302 we ought to be in a better position wrt. usability for this too. |
Alternative to encode/httpx#1196, prompted by encode/httpx#1196 (comment)
Closes encode/httpx#1141
This PR adds off-by-default "retry on connection failure" capability to the connection pool, using a
retries=<int>
option. Also includes an exponential backoff mechanism, with a fixed backoff factor of 0.5 for now (so, 0s, 0.5s, 1.0s, 2.0s, 4.0s, etc).We add it at the transport layer, as close to opening sockets as possible, so that connect retries don't interact with the connection pooling logic, so that we do "acquire a connection, open a socket, open a socket, …, release the connection".
(We're in a better position now to add this feature now, because we have a
backend
option on the connection pool transport. This PR tweaks it a bit so we can pass a full-fledged backend instance, rather than only a backend name. Then we build and provide a mock backend that raises exception on-demand, for testing purposes.)(The diff looks quite big, but everything is unasynced, so duplicated, and test code is a bit large too, so…)
Once merged, we'll be able to document this on the HTTPX side, in a new "Retries" section in "Advanced Usage". For now usage will be a bit involved, but once
httpx.HTTPTransport()
lands (encode/httpx#1302) things will be easier UX-wise.