-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Max_duration is not respected when retry_count > 1 (http-client) #46316
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
Comments
As reported on [#46316](symfony/symfony#46316), when a request gets a successful response in further attempts, the `max_duration` is not respected and the request may take longer than the value especified here. My way to solve the issue was by reducing the timeout option in future requests, making it smaller in every attempt. By doing so, the total time of a $client->request will never be much longer than `max_duration`. Perhaps a second or two maybe, due to the waiting time between requests, but not as much as the `timeout`.
As reported on symfony#46316, when a request gets a successful response in further attempts, the max_duration is not respected and the request may take longer than the value specified here. My way to solve the issue was by reducing the timeout option in future requests, making it smaller in every attempt. By doing so, the total time of a $client->request will never be much longer than max_duration. Perhaps a second or two maybe, due to the waiting time between requests, but not as much as the timeout.
I'm not sure the behavior you describe is the expected one. To me, it's not obvious that a group of retries should respect a single max duration. Max duration is defined as applicable to one request and it's never been defined to a series of request. I think you'd better achieve what you want by implementing the control of the duration on your side, in loop like: foreach ($client->stream($response, $idleTimeout) as $chunk) {
// measure total duration here and exit when you want
} |
Thanks for your precious time in responding to me @nicolas-grekas. Quoting...
But I never worked with the stream method.. I will definitively give it a try tomorrow and update the topic here. Maybe I didn't understood the docs properly. |
/cc @jderusse any opinion on this? We could patch RetryableHttpClient so that is reduces the max_duration of retries by the duration of the failed requests. |
Technically, that means the
|
For the start time, it exists already: |
Hi @nicolas-grekas. I played the last 2 hours with the I did something like this..
My test case scenario is:
Because this is a "place order" request and involves credit card capture, I may need to send a $response->cancel() if one of the attempts times out in order to avoid duplicated orders/charges. Is there a way to retry the request within the foreach you mentioned? Thank you one more time. |
See #46382 |
…with async decorators (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [HttpClient] Honor "max_duration" when replacing requests with async decorators | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46316 | License | MIT | Doc PR | - Instead of #46330 Commits ------- c81d116 [HttpClient] Honor "max_duration" when replacing requests with async decorators
Symfony version(s) affected
5.4.8
Description
Let's say you have an API endpoint that always fails on the first request, and succeed on the second attempt.
Every request takes 30 seconds to be returned by the API.
If you make a Retryable HttpRequest, you can define
timeout
andmax_duration
to 40 seconds.But it will not be respected, because when doing the second attempt, symfony still waits up to 40 seconds to get a response.
So you can expect this part of code to take 60 seconds to respond with no issues, instead of having a timeout error.
How to reproduce
sleep.php
file:php -S localhost:8888
in the folder of the file abovebin/console app:test
and note that it will succeed on the second attempt after 60 seconds.Possible Solution
We may need to work on AmpHttpClient or RetryableHttpClient to use the time left on the other requests.
I posted a half solution here that may be useful to get the total time of the request, including the waiting time between the attempts.
But it's far from the ideal solution.
Additional Context
In my case, I have a controller that makes http requests to another endpoint.
The users that call this controller, expect it to return a response in 45 seconds. However, after implementing the RetryableHttpClient, I'm having cases where the request is processed by the other endpoint in the second or third attempt, but my users get a timeout exception.
It happens because the first request to the other endpoint takes less than 45 seconds, but both calls take more than that.
The text was updated successfully, but these errors were encountered: