forked from aws/aws-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aws#566 from aws/retries-for-complete-mup-errors
Prevents S3 CompleteMultipartUpload failures by retrying the request.
- Loading branch information
Showing
4 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Aws\S3; | ||
|
||
use Guzzle\Http\Exception\HttpException; | ||
use Guzzle\Http\Message\RequestInterface; | ||
use Guzzle\Http\Message\EntityEnclosingRequestInterface; | ||
use Guzzle\Http\Message\Response; | ||
use Guzzle\Plugin\Backoff\BackoffStrategyInterface; | ||
use Guzzle\Plugin\Backoff\AbstractBackoffStrategy; | ||
|
||
/** | ||
* Retries CompleteMultipartUpload requests in the case of failure. | ||
* | ||
* From the S3 API Documentation: | ||
* | ||
* Processing of a Complete Multipart Upload request could take several | ||
* minutes to complete. After Amazon S3 begins processing the request, it | ||
* sends an HTTP response header that specifies a 200 OK response. While | ||
* processing is in progress, Amazon S3 periodically sends whitespace | ||
* characters to keep the connection from timing out. Because a request | ||
* could fail after the initial 200 OK response has been sent, it is | ||
* important that you check the response body to determine whether the | ||
* request succeeded. Note that if Complete Multipart Upload fails, | ||
* applications should be prepared to retry the failed requests. | ||
*/ | ||
class IncompleteMultipartUploadChecker extends AbstractBackoffStrategy | ||
{ | ||
public function __construct(BackoffStrategyInterface $next = null) | ||
{ | ||
if ($next) { | ||
$this->setNext($next); | ||
} | ||
} | ||
|
||
public function makesDecision() | ||
{ | ||
return true; | ||
} | ||
|
||
protected function getDelay( | ||
$retries, | ||
RequestInterface $request, | ||
Response $response = null, | ||
HttpException $e = null | ||
) { | ||
if ($response && $request->getMethod() === 'POST' | ||
&& $request instanceof EntityEnclosingRequestInterface | ||
&& $response->getStatusCode() == 200 | ||
&& strpos($request->getBody(), '<CompleteMultipartUpload xmlns') !== false | ||
&& strpos($response->getBody(), '<CompleteMultipartUploadResult xmlns') === false | ||
) { | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
HTTP/1.1 200 OK | ||
x-amz-id-2: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
x-amz-request-id: XXXXXXXXXXXXXXXX | ||
Date: Mon, 30 Jul 2012 20:01:57 GMT | ||
Content-Type: application/xml | ||
Server: AmazonS3 | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
|
||
|
||
|
||
|
||
|
||
<Error> | ||
<Code>InternalError</Code> | ||
<Message>We encountered an internal error. Please try again.</Message> | ||
<RequestId>656c76696e6727732072657175657374</RequestId> | ||
<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId> | ||
</Error> |