Skip to content
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

[HttpClient] Timeout are not always respected #33017

Closed
lyrixx opened this issue Aug 7, 2019 · 2 comments

Comments

@lyrixx
Copy link
Member

commented Aug 7, 2019

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?!

@lyrixx

This comment has been minimized.

Copy link
Member Author

commented Aug 7, 2019

Note: It's the same with the max_duration option

nicolas-grekas added a commit that referenced this issue Aug 8, 2019

bug #33022 [HttpClient] Remove CURLOPT_CONNECTTIMEOUT_MS curl opt (ly…
…rixx)

This PR was merged into the 4.3 branch.

Discussion
----------

[HttpClient] Remove CURLOPT_CONNECTTIMEOUT_MS curl opt

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #33017
| License       | MIT
| Doc PR        | -

Commits
-------

e289723 [HttpClient] Remove CURLOPT_CONNECTTIMEOUT_MS curl opt
@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Aug 8, 2019

Note: It's the same with the max_duration option

that's expected for max_duration as there is no other time than the wall time to define it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.