Skip to content

Commit 6844cb8

Browse files
bug symfony#38523 [HttpClient] Fix multiple timeout with multiple retry (jderusse)
This PR was merged into the 5.x branch. Discussion ---------- [HttpClient] Fix multiple timeout with multiple retry | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | / | License | MIT | Doc PR | / Fix symfony#38518 when retryied request also failed. Commits ------- 79a9392 Fix multiple timeou with multiple retry
2 parents e4024e8 + 79a9392 commit 6844cb8

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ public function __construct(HttpClientInterface $client, string $method, string
5050
return false;
5151
}
5252

53-
foreach (self::stream([$response]) as $chunk) {
54-
if ($chunk->isTimeout() && $response->passthru) {
55-
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
56-
return !$chunk->isFirst();
53+
while (true) {
54+
foreach (self::stream([$response]) as $chunk) {
55+
if ($chunk->isTimeout() && $response->passthru) {
56+
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
57+
if ($chunk->isFirst()) {
58+
return false;
59+
}
60+
}
61+
62+
continue 2;
5763
}
5864

59-
return true;
60-
}
61-
62-
if ($chunk->isFirst()) {
63-
break;
65+
if ($chunk->isFirst()) {
66+
return false;
67+
}
6468
}
6569
}
6670

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,20 @@ public function testBufferPurePassthru()
215215

216216
public function testRetryTimeout()
217217
{
218-
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
218+
$cpt = 0;
219+
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use (&$cpt) {
219220
try {
220221
$this->assertTrue($chunk->isTimeout());
221222
yield $chunk;
222223
} catch (TransportExceptionInterface $e) {
223-
$context->passthru();
224-
$context->getResponse()->cancel();
225-
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 1]);
224+
if ($cpt++ < 3) {
225+
$context->getResponse()->cancel();
226+
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
227+
} else {
228+
$context->passthru();
229+
$context->getResponse()->cancel();
230+
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 1]);
231+
}
226232
}
227233
});
228234

0 commit comments

Comments
 (0)