-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Added RetryHttpClient #38182
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
Conversation
7a08712
to
92d2a66
Compare
Nice feature! A quick question: would end-users need to change their code to use this special HTTP client instead of the default one? If that's the case, I find it too cumbersome. What if we provide this feature via a config option of any HTTP client? 'retry_failed' => [
'max_retries' => 2, // -1 = infinite
'wait_after_retries' => 10, // seconds
'retry_model' => 'exponential', // 'linear' or 'exponential' (== "exponential backoff")
] |
Refactor implementation to use |
01a34d7
to
5b6d854
Compare
675a7f5
to
3a5f3f5
Compare
This PR is RFR, thank you for the suggestion @javiereguiluz and thank you @nicolas-grekas for your help. |
src/Symfony/Component/HttpClient/Retry/MultiplierRetryStrategy.php
Outdated
Show resolved
Hide resolved
5db8746
to
75d727f
Compare
src/Symfony/Component/HttpClient/Retry/MultiplierRetryStrategy.php
Outdated
Show resolved
Hide resolved
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.
In case of a 429 response, should we automatically try to read the Retry-After
header ?
Also, should we have a single RetryStrategyInterface covering both the check whether retry should be done and the computation of the backoff delay ? Or should they be separate interfaces that can be replaced separately ? I see potential for customizing conditions for the retry while still keeping exponential backoff (for instance checking the request method to retry only idempotent requests)
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/Retry/MultiplierRetryStrategy.php
Outdated
Show resolved
Hide resolved
Btw, do we have access to the request when deciding to retry ? Or is is impossible to implement the case of attempting retry only for idempotent methods ? |
Good idea, I added it. (I'm not sure how it should behave in case of conflict with delay computed by the backof...)
Yeah, I hesitate a lot to split this interface in 2:
|
https://github.com/hashicorp/go-retryablehttp makes the
If we look in the go implementation (see just above in my message), the handling of a maximum number of retry is managed by the client itself rather than being delegated to an extension point (there isn't really a point changing the way a |
src/Symfony/Component/HttpClient/Retry/RetryStrategyInterface.php
Outdated
Show resolved
Hide resolved
f54918e
to
c52cbf0
Compare
I split the interface in 2:
|
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.
Some more thoughts :)
Could deserve a line in the changelog of fwb.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
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.
Just a super minor
240e18d
to
c9845ff
Compare
b9ccf37
to
6523df7
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
private function registerHttpClientRetry(array $retryOptions, string $name, ContainerBuilder $container) | ||
{ | ||
if (!class_exists(RetryHttpClient::class)) { | ||
throw new LogicException('Retry failed request support cannot be enabled as the component is not installed in the right version. Try running "composer require symfony/http-client:^5.2".'); |
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.
Retry failed request support cannot be enabled as version 5.2+ of the HTTP Client component is required.
I would remove the composer command suggestion.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
ccad3ed
to
923633a
Compare
Thank you @jderusse. |
This PR adds a new HttpClient decorator to automatically retry failed requests.
When calling API, A very small % of requests are expected to timeout due to transient network issues. Some providers like AWS recommends retrying these requests and use a lower connection timeout so that the clients can fail fast and retry.
I used the almost the same configuration as Messenger