Retry on S3 HTTP 504 Gateway Timeout status codes

RiakCS using the S3 interface occasionally surfaces these status
codes.
This commit is contained in:
Andrew Gaul 2014-03-13 11:01:25 -07:00
parent 33f244dbab
commit a7fa3b9c62
2 changed files with 23 additions and 1 deletions

View File

@ -50,7 +50,8 @@ public class AWSServerErrorRetryHandler extends BackoffLimitedRetryHandler {
@Override
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
if (response.getStatusCode() == 503) {
switch (response.getStatusCode()) {
case 503: // Service Unavailable
// Content can be null in the case of HEAD requests
if (response.getPayload() != null) {
closeClientButKeepContentStream(response);
@ -59,6 +60,9 @@ public class AWSServerErrorRetryHandler extends BackoffLimitedRetryHandler {
return shouldRetryRequestOnError(command, response, error);
}
}
break;
case 504: // Gateway Timeout
return super.shouldRetryRequest(command, response);
}
return false;
}

View File

@ -23,6 +23,7 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicInteger;
@ -112,4 +113,21 @@ public class AWSServerErrorRetryHandlerTest {
}
@Test
public void test504DoesRetry() {
AWSUtils utils = createMock(AWSUtils.class);
HttpCommand command = createMock(HttpCommand.class);
expect(command.getFailureCount()).andReturn(1).anyTimes();
expect(command.incrementFailureCount()).andReturn(1);
expect(command.isReplayable()).andReturn(true);
replay(utils, command);
AWSServerErrorRetryHandler retry = new AWSServerErrorRetryHandler(utils,
ImmutableSet.<String> of());
assertTrue(retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(504).build()));
verify(utils, command);
}
}