Fix multiple timeou with multiple retry

This commit is contained in:
Jérémy Derussé 2020-10-12 11:08:06 +02:00
parent 2a70f68847
commit 79a9392468
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
2 changed files with 23 additions and 13 deletions

View File

@ -50,17 +50,21 @@ final class AsyncResponse implements ResponseInterface, StreamableInterface
return false;
}
foreach (self::stream([$response]) as $chunk) {
if ($chunk->isTimeout() && $response->passthru) {
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
return !$chunk->isFirst();
while (true) {
foreach (self::stream([$response]) as $chunk) {
if ($chunk->isTimeout() && $response->passthru) {
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
if ($chunk->isFirst()) {
return false;
}
}
continue 2;
}
return true;
}
if ($chunk->isFirst()) {
break;
if ($chunk->isFirst()) {
return false;
}
}
}

View File

@ -215,14 +215,20 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
public function testRetryTimeout()
{
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
$cpt = 0;
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use (&$cpt) {
try {
$this->assertTrue($chunk->isTimeout());
yield $chunk;
} catch (TransportExceptionInterface $e) {
$context->passthru();
$context->getResponse()->cancel();
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 1]);
if ($cpt++ < 3) {
$context->getResponse()->cancel();
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
} else {
$context->passthru();
$context->getResponse()->cancel();
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 1]);
}
}
});