symfony: [HttpClient] TransportException on multiple requests

Symfony version(s) affected: branch 4.4

Description

I know this is usually a server issue, But Im confident it isn’t. I make a request like:

$client = new CurlHttpClient();
$response = $client->request(
    'GET',
    'https://foo.eu.auth0.com/api/v2/users?search_engine=v3&q=email%3A%22tobias%2Bmanager%40happyr.com%22',
    [
        'headers'=> ['Authorization' => 'Bearer eyJ0eXAiOiJ...'],
    ]
);

$x = $response->getStatusCode();
//$this->assertSame(200, $x);

$response = $client->request(
    'DELETE',
    'https://foo.eu.auth0.com/api/v2/users/auth0%7C5d2f790e26a0cf1347f7a/roles',
    [
        'headers'=> ['content-type' => 'application/json', 'Authorization' => 'Bearer eyJ0eXAiOiJ...'],
        'body' => '{"roles":["rol_ipXgFzjd2cH5"]}',
    ]
);

$y = $response->getStatusCode();
//$this->assertSame(204, $y);

Notes:

  • A) I tried doing the exact same request in Buzz and it works perfectly…
  • B) My Authorization header is 1034 characters long.
  • C) If I remove the content-type header from the second request then it works
  • D) If I only do the DELETE request, it also works.

The exception

Symfony\Component\HttpClient\Exception\TransportException: Failed sending data to the peer for "https://foo.eu.auth0.com/api/v2/users/auth0%7C5d2939f790e26a0cf1347f7a/roles".

src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php:105
src/Symfony/Component/HttpClient/Response/CurlResponse.php:124
src/Symfony/Component/HttpClient/Response/ResponseTrait.php:67
src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php:95

Caused by
Symfony\Component\HttpClient\Exception\TransportException: Failed sending data to the peer for "https://foo.eu.auth0.com/api/v2/users/auth0%7C5d2939f790e26a0cf1347f7a/roles".

src/Symfony/Component/HttpClient/Response/CurlResponse.php:262
src/Symfony/Component/HttpClient/Response/ResponseTrait.php:289
src/Symfony/Component/HttpClient/Response/CurlResponse.php:124
src/Symfony/Component/HttpClient/Response/ResponseTrait.php:67
src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php:95

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (13 by maintainers)

Most upvoted comments

Nicolas and I debugged this together: Running php --ri curl | grep "cURL Information" will give you the version of curl you are using. This bug in not present in 7.58.0 but it is in 7.64.0. Ie, the higher version is broken.

When using HTTP 1.1 instead of HTTP 2.0 it was working. That will lead us to believe that there is a bug in curl when using h2+reusing connections.


My workaround at the moment is to use HTTP 1.1.

$client = new CurlHttpClient([
    'http_version'=>'1.1'
]);

or if one uses the component with the FrameworkBundle:

framework:
  http_client:
    default_options:
      http_version: "1.1"

Thank you for your response.

Here is the debug info from both requests. I caught the exception from the second $response->getStatusCode(); and then var_dump($response->getInfo('debug'));:

string(3567) "* Expire in 0 ms for 6 (transfer 0x7fe450010e00)
* Expire in 60000 ms for 2 (transfer 0x7fe450010e00)
* Expire in 5000 ms for 1 (transfer 0x7fe450010e00)
* Expire in 5000 ms for 1 (transfer 0x7fe450010e00)
* Expire in 5000 ms for 1 (transfer 0x7fe450010e00)
* Expire in 4948 ms for 1 (transfer 0x7fe450010e00)
* Expire in 4948 ms for 1 (transfer 0x7fe450010e00)
* Expire in 4948 ms for 1 (transfer 0x7fe450010e00)
* Expire in 5000 ms for 1 (transfer 0x7fe450010e00)
* Expire in 5000 ms for 1 (transfer 0x7fe45001"...

----

string(2311) "* Expire in 0 ms for 6 (transfer 0x7fe47002dc00)
* Expire in 60000 ms for 2 (transfer 0x7fe47002dc00)
* Found bundle for host foo.eu.auth0.com: 0x7fe467d44430 [can multiplex]
* Conn: 0 (0x7fe478037c00) Receive pipe weight: (-1/0), penalized: FALSE
* Multiplexed connection found!
* Found connection 0, with requests in the pipe (1)
* Re-using existing connection! (#0) with host foo.eu.auth0.com
* Using Stream ID: 3 (easy handle 0x7fe47002dc00)
> DELETE /api/v2/users/auth0% 7C5d2f790e26a0cf1347f7a"...