Skip to content

Commit d413baa

Browse files
Merge branch '4.4' into 5.3
* 4.4: [HttpClient] Don't reset timeout counter when initializing requests
2 parents b33bd44 + 843c9d7 commit d413baa

File tree

8 files changed

+46
-4
lines changed

8 files changed

+46
-4
lines changed

src/Symfony/Component/HttpClient/Response/AmpResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti
125125
}
126126
};
127127

128+
$multi->lastTimeout = null;
128129
$multi->openHandles[$id] = $id;
129130
++$multi->responseCount;
130131

src/Symfony/Component/HttpClient/Response/CommonResponseTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ public function __wakeup()
145145
*/
146146
abstract protected function close(): void;
147147

148-
private static function initialize(self $response, float $timeout = null): void
148+
private static function initialize(self $response): void
149149
{
150150
if (null !== $response->getInfo('error')) {
151151
throw new TransportException($response->getInfo('error'));
152152
}
153153

154154
try {
155-
if (($response->initializer)($response, $timeout)) {
156-
foreach (self::stream([$response], $timeout) as $chunk) {
155+
if (($response->initializer)($response, -0.0)) {
156+
foreach (self::stream([$response], -0.0) as $chunk) {
157157
if ($chunk->isFirst()) {
158158
break;
159159
}

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
170170
};
171171

172172
// Schedule the request in a non-blocking way
173+
$multi->lastTimeout = null;
173174
$multi->openHandles[$id] = [$ch, $options];
174175
curl_multi_add_handle($multi->handle, $ch);
175176

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ private function open(): void
196196
}
197197

198198
$host = parse_url($this->info['redirect_url'] ?? $this->url, \PHP_URL_HOST);
199+
$this->multi->lastTimeout = null;
199200
$this->multi->openHandles[$this->id] = [&$this->pauseExpiry, $h, $this->buffer, $this->onProgress, &$this->remaining, &$this->info, $host];
200201
$this->multi->hosts[$host] = 1 + ($this->multi->hosts[$host] ?? 0);
201202
}

src/Symfony/Component/HttpClient/Response/TransportResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function doDestruct()
138138
$this->shouldBuffer = true;
139139

140140
if ($this->initializer && null === $this->info['error']) {
141-
self::initialize($this, -0.0);
141+
self::initialize($this);
142142
$this->checkStatusCode();
143143
}
144144
}

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
278278
$this->markTestSkipped('Real transport required');
279279
break;
280280

281+
case 'testTimeoutOnInitialize':
281282
case 'testTimeoutOnDestruct':
282283
$this->markTestSkipped('Real transport required');
283284
break;

src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function testInformationalResponseStream()
2626
$this->markTestSkipped('NativeHttpClient doesn\'t support informational status codes.');
2727
}
2828

29+
public function testTimeoutOnInitialize()
30+
{
31+
$this->markTestSkipped('NativeHttpClient doesn\'t support opening concurrent requests.');
32+
}
33+
2934
public function testTimeoutOnDestruct()
3035
{
3136
$this->markTestSkipped('NativeHttpClient doesn\'t support opening concurrent requests.');

src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,39 @@ public function testTimeoutWithActiveConcurrentStream()
835835
}
836836
}
837837

838+
public function testTimeoutOnInitialize()
839+
{
840+
$p1 = TestHttpServer::start(8067);
841+
$p2 = TestHttpServer::start(8077);
842+
843+
$client = $this->getHttpClient(__FUNCTION__);
844+
$start = microtime(true);
845+
$responses = [];
846+
847+
$responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]);
848+
$responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]);
849+
$responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]);
850+
$responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]);
851+
852+
try {
853+
foreach ($responses as $response) {
854+
try {
855+
$response->getContent();
856+
$this->fail(TransportExceptionInterface::class.' expected');
857+
} catch (TransportExceptionInterface $e) {
858+
}
859+
}
860+
$responses = [];
861+
862+
$duration = microtime(true) - $start;
863+
864+
$this->assertLessThan(1.0, $duration);
865+
} finally {
866+
$p1->stop();
867+
$p2->stop();
868+
}
869+
}
870+
838871
public function testTimeoutOnDestruct()
839872
{
840873
$p1 = TestHttpServer::start(8067);

0 commit comments

Comments
 (0)