diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index ae596ba7eefd1..4ee683e9ec5a2 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -148,6 +148,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null, }; // Schedule the request in a non-blocking way + $multi->lastTimeout = null; $multi->openHandles[$id] = [$ch, $options]; curl_multi_add_handle($multi->handle, $ch); diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index e87402f0ad8dc..c186900c5e658 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -183,6 +183,7 @@ private function open(): void return; } + $this->multi->lastTimeout = null; $this->multi->openHandles[$this->id] = [$h, $this->buffer, $this->onProgress, &$this->remaining, &$this->info]; } diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 0f041d4d02d21..b70c1e885a869 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -233,15 +233,15 @@ abstract protected static function perform(ClientState $multi, array &$responses */ abstract protected static function select(ClientState $multi, float $timeout): int; - private static function initialize(self $response, float $timeout = null): void + private static function initialize(self $response): void { if (null !== $response->info['error']) { throw new TransportException($response->info['error']); } try { - if (($response->initializer)($response, $timeout)) { - foreach (self::stream([$response], $timeout) as $chunk) { + if (($response->initializer)($response, -0.0)) { + foreach (self::stream([$response], -0.0) as $chunk) { if ($chunk->isFirst()) { break; } @@ -304,7 +304,7 @@ private function doDestruct() $this->shouldBuffer = true; if ($this->initializer && null === $this->info['error']) { - self::initialize($this, -0.0); + self::initialize($this); $this->checkStatusCode(); } } diff --git a/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php index 47234d71de0e9..d56f20aec206d 100644 --- a/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php @@ -157,6 +157,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface $this->markTestSkipped('Real transport required'); break; + case 'testTimeoutOnInitialize': case 'testTimeoutOnDestruct': $this->markTestSkipped('Real transport required'); break; diff --git a/src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php index 2f76cc91c609f..a03b2db8c99b4 100644 --- a/src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php @@ -26,6 +26,11 @@ public function testInformationalResponseStream() $this->markTestSkipped('NativeHttpClient doesn\'t support informational status codes.'); } + public function testTimeoutOnInitialize() + { + $this->markTestSkipped('NativeHttpClient doesn\'t support opening concurrent requests.'); + } + public function testTimeoutOnDestruct() { $this->markTestSkipped('NativeHttpClient doesn\'t support opening concurrent requests.'); diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index 1062c7c024b4d..7ebf055d75701 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -810,6 +810,39 @@ public function testTimeoutWithActiveConcurrentStream() } } + public function testTimeoutOnInitialize() + { + $p1 = TestHttpServer::start(8067); + $p2 = TestHttpServer::start(8077); + + $client = $this->getHttpClient(__FUNCTION__); + $start = microtime(true); + $responses = []; + + $responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]); + $responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]); + $responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]); + $responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]); + + try { + foreach ($responses as $response) { + try { + $response->getContent(); + $this->fail(TransportExceptionInterface::class.' expected'); + } catch (TransportExceptionInterface $e) { + } + } + $responses = []; + + $duration = microtime(true) - $start; + + $this->assertLessThan(1.0, $duration); + } finally { + $p1->stop(); + $p2->stop(); + } + } + public function testTimeoutOnDestruct() { $p1 = TestHttpServer::start(8067); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy