Closed
Description
Symfony version(s) affected: 4.3 to master
Description
Timeout are not really respected.
Some request takes less than the timeout, but an exception is thrown.
How to reproduce
use Symfony\Component\HttpClient\HttpClient;
$httpClient = HttpClient::create();
$response = $httpClient->request('GET', 'http://httpbin.org/get', [
'timeout' => 1,
]);
sleep(2);
dump($response->getStatusCode());
exception
Fatal error: Uncaught Symfony\Component\HttpClient\Exception\TransportException: Timeout was reached for "http://httpbin.org/get". in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Response/CurlResponse.php:263
Stack trace:
#0 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Response/ResponseTrait.php(298): Symfony\Component\HttpClient\Response\CurlResponse::perform(Object(Symfony\Component\HttpClient\Internal\CurlClientState), Array)
#1 [internal function]: Symfony\Component\HttpClient\Response\CurlResponse::stream(Array)
#2 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Response/CurlResponse.php(124): Generator->current()
#3 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Response/ResponseTrait.php(71): Symfony\Component\HttpClient\Response\CurlResponse::Symfony\Component\HttpClient\Response\{closure}(Object(Symfony\Component\HttpClient\Response\CurlResponse))
#4 /home/gregoire/dev/github.com/lyrixx/symfony/test.php(12): Symfony\Component\HttpClient\Response\CurlResponse->getStatusCode()
#5 {main}
Next Symfony\Component\HttpClient\Exception\TransportException: Timeout was reached for "http://httpbin.org/get". in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php:105
Stack trace:
#0 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Response/CurlResponse.php(124): Symfony\Component\HttpClient\Chunk\ErrorChunk->__destruct()
#1 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Response/ResponseTrait.php(71): Symfony\Component\HttpClient\Response\CurlResponse::Symfony\Component\HttpClient\Response\{closure}(Object(Symfony\Component\HttpClient\Response\CurlResponse))
#2 /home/gregoire/dev/github.com/lyrixx/symfony/test.php(12): Symfony\Component\HttpClient\Response\CurlResponse->getStatusCode()
#3 {main}
thrown in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php on line 105
Possible Solution
Do not use curl timeout, but implement things by hand?!