Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f3bdeb

Browse filesBrowse files
[HttpClient] Don't reset timeout counter when initializing requests
1 parent 2381e0d commit 8f3bdeb
Copy full SHA for 8f3bdeb

File tree

Expand file treeCollapse file tree

6 files changed

+45
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+45
-4
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/CurlResponse.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
148148
};
149149

150150
// Schedule the request in a non-blocking way
151+
$multi->lastTimeout = null;
151152
$multi->openHandles[$id] = [$ch, $options];
152153
curl_multi_add_handle($multi->handle, $ch);
153154

Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/NativeResponse.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private function open(): void
183183
return;
184184
}
185185

186+
$this->multi->lastTimeout = null;
186187
$this->multi->openHandles[$this->id] = [$h, $this->buffer, $this->onProgress, &$this->remaining, &$this->info];
187188
}
188189

Collapse file

‎src/Symfony/Component/HttpClient/Response/ResponseTrait.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/ResponseTrait.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ abstract protected static function perform(ClientState $multi, array &$responses
233233
*/
234234
abstract protected static function select(ClientState $multi, float $timeout): int;
235235

236-
private static function initialize(self $response, float $timeout = null): void
236+
private static function initialize(self $response): void
237237
{
238238
if (null !== $response->info['error']) {
239239
throw new TransportException($response->info['error']);
240240
}
241241

242242
try {
243-
if (($response->initializer)($response, $timeout)) {
244-
foreach (self::stream([$response], $timeout) as $chunk) {
243+
if (($response->initializer)($response, -0.0)) {
244+
foreach (self::stream([$response], -0.0) as $chunk) {
245245
if ($chunk->isFirst()) {
246246
break;
247247
}
@@ -304,7 +304,7 @@ private function doDestruct()
304304
$this->shouldBuffer = true;
305305

306306
if ($this->initializer && null === $this->info['error']) {
307-
self::initialize($this, -0.0);
307+
self::initialize($this);
308308
$this->checkStatusCode();
309309
}
310310
}
Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
157157
$this->markTestSkipped('Real transport required');
158158
break;
159159

160+
case 'testTimeoutOnInitialize':
160161
case 'testTimeoutOnDestruct':
161162
$this->markTestSkipped('Real transport required');
162163
break;
Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php
+5Lines 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.');
Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,39 @@ public function testTimeoutWithActiveConcurrentStream()
810810
}
811811
}
812812

813+
public function testTimeoutOnInitialize()
814+
{
815+
$p1 = TestHttpServer::start(8067);
816+
$p2 = TestHttpServer::start(8077);
817+
818+
$client = $this->getHttpClient(__FUNCTION__);
819+
$start = microtime(true);
820+
$responses = [];
821+
822+
$responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]);
823+
$responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]);
824+
$responses[] = $client->request('GET', 'http://localhost:8067/timeout-header', ['timeout' => 0.25]);
825+
$responses[] = $client->request('GET', 'http://localhost:8077/timeout-header', ['timeout' => 0.25]);
826+
827+
try {
828+
foreach ($responses as $response) {
829+
try {
830+
$response->getContent();
831+
$this->fail(TransportExceptionInterface::class.' expected');
832+
} catch (TransportExceptionInterface $e) {
833+
}
834+
}
835+
$responses = [];
836+
837+
$duration = microtime(true) - $start;
838+
839+
$this->assertLessThan(1.0, $duration);
840+
} finally {
841+
$p1->stop();
842+
$p2->stop();
843+
}
844+
}
845+
813846
public function testTimeoutOnDestruct()
814847
{
815848
$p1 = TestHttpServer::start(8067);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.