Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Idle timeout reached with negative default_socket_timeout #44477

Copy link
Copy link
Closed
@caugner

Description

@caugner
Issue body actions

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:

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:

} 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
 (...)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.