Skip to content

Commit

Permalink
Merge pull request aws#844 from jeskew/fix/only-check-for-reverse-slo…
Browse files Browse the repository at this point in the history
…wloris-responses-on-400s

Ensure errors with unparseable responses are retried when idempotent
  • Loading branch information
jeskew committed Dec 11, 2015
2 parents 3ac0213 + b31dbcc commit 9fee106
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/S3/S3Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,10 @@ public static function _applyRetryConfig($value, $_, HandlerList $list)
} elseif ($error instanceof AwsException
&& $retries < $maxRetries
) {
if ($error->getResponse()) {
if (
$error->getResponse()
&& $error->getResponse()->getStatusCode() >= 400
) {
return strpos(
$error->getResponse()->getBody(),
'Your socket connection to the server'
Expand Down
33 changes: 33 additions & 0 deletions tests/S3/S3ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,4 +755,37 @@ public function testNetworkingErrorsAreNotRetriedOnNonIdempotentCommands()

$this->assertEquals(0, $retries);
}

public function testErrorsWithUnparseableBodiesCanBeRetried()
{
$networkingError = $this->getMockBuilder(RequestException::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();

$retries = 11;
$client = new S3Client([
'version' => 'latest',
'region' => 'us-west-2',
'retries' => $retries,
'http_handler' => function () use (&$retries, $networkingError) {
if (0 === --$retries) {
return new FulfilledPromise(new Response);
}

return new RejectedPromise([
'connection_error' => false,
'exception' => $networkingError,
'response' => new Response(200, [], openssl_random_pseudo_bytes(2048)),
]);
},
]);

$client->getObject([
'Bucket' => 'bucket',
'Key' => 'key',
]);

$this->assertEquals(0, $retries);
}
}

0 comments on commit 9fee106

Please sign in to comment.