-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected
5.4.0
Description
We have set PHP's configuration directive default_socket_timeout
to -1
(meaning infinite timeout), and noticed that all requests created with symfony/http-client
failed with a "Idle timeout reached" exception.
This looked like #44198, but the issue persisted beyond upgrading from 5.3.7 to 5.4.0.
How to reproduce
ini_set('default_socket_timeout', '-1');
$response = \Symfony\Component\HttpClient\HttpClient::create()->request('GET', 'https://symfony.com');
dd($response->getStatusCode());
// Symfony\Component\HttpClient\Exception\TimeoutException with message 'Idle timeout reached for "https://symfony.com/".'
Possible Solution
The HttpClientTrait
falls back to the default_socket_timeout
value from PHP:
$options['timeout'] = (float) ($options['timeout'] ?? ini_get('default_socket_timeout')); |
However, the TransportResponseTrait
does not seem to handle this well:
$timeoutMin = min($timeoutMin, $response->timeout, 1); |
Consequently (I think), the following usleep()
call is skipped:
symfony/src/Symfony/Component/HttpClient/Response/TransportResponseTrait.php
Lines 312 to 314 in d2600e8
if (-1 === self::select($multi, min($timeoutMin, $timeoutMax - $elapsedTimeout))) { | |
usleep(min(500, 1E6 * $timeoutMin)); | |
} |
So curl may not have a chance to actually proceed with the request, and since no time is elapsed, $elapsedTimeout
and $timeoutMax
are still both 0
, causing the following ErrorChunk
:
symfony/src/Symfony/Component/HttpClient/Response/TransportResponseTrait.php
Lines 197 to 199 in d2600e8
} elseif ($elapsedTimeout >= $timeoutMax) { | |
$multi->handlesActivity[$j] = [new ErrorChunk($response->offset, sprintf('Idle timeout reached for "%s".', $response->getInfo('url')))]; | |
$multi->lastTimeout ?? $multi->lastTimeout = $lastActivity; |
Additional Context
Originally posted here: meilisearch/meilisearch-php#262
Symfony\Component\HttpClient\Exception\TimeoutException: Idle timeout reached for "http://meilisearch:7700/indexes/projects/documents?primaryKey=id".
/var/www/html/vendor/symfony/http-client/Chunk/ErrorChunk.php:62
/var/www/html/vendor/symfony/http-client/Response/CommonResponseTrait.php:150
/var/www/html/vendor/symfony/http-client/Response/TransportResponseTrait.php:55
/var/www/html/vendor/symfony/http-client/Psr18Client.php:100
(...)