diff --git a/gcsio/src/test/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageTest.java b/gcsio/src/test/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageTest.java index f3a1fdac2..798b7476a 100644 --- a/gcsio/src/test/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageTest.java +++ b/gcsio/src/test/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageTest.java @@ -34,7 +34,6 @@ import static com.google.cloud.hadoop.gcsio.TrackingHttpRequestInitializer.resumableUploadChunkRequestString; import static com.google.cloud.hadoop.gcsio.TrackingHttpRequestInitializer.resumableUploadRequestString; import static com.google.cloud.hadoop.gcsio.TrackingHttpRequestInitializer.uploadRequestString; -import static com.google.cloud.hadoop.util.RetryHttpInitializer.HTTP_REQUEST_TIMEOUT; import static com.google.cloud.hadoop.util.testing.MockHttpTransportHelper.dataResponse; import static com.google.cloud.hadoop.util.testing.MockHttpTransportHelper.emptyResponse; import static com.google.cloud.hadoop.util.testing.MockHttpTransportHelper.inputStreamResponse; @@ -432,7 +431,7 @@ public void upload_retry_requestTimeout() throws Exception { mockTransport( emptyResponse(HttpStatusCodes.STATUS_CODE_NOT_FOUND), resumableUploadResponse(BUCKET_NAME, OBJECT_NAME), - emptyResponse(HTTP_REQUEST_TIMEOUT), + emptyResponse(408), // HTTP 408 Request Timeout jsonDataResponse( newStorageObject(BUCKET_NAME, OBJECT_NAME) .setSize(BigInteger.valueOf(testData.length)))); diff --git a/util/src/main/java/com/google/cloud/hadoop/util/RetryHttpInitializer.java b/util/src/main/java/com/google/cloud/hadoop/util/RetryHttpInitializer.java index 5b80069bc..15c8d62f4 100644 --- a/util/src/main/java/com/google/cloud/hadoop/util/RetryHttpInitializer.java +++ b/util/src/main/java/com/google/cloud/hadoop/util/RetryHttpInitializer.java @@ -35,6 +35,7 @@ import com.google.common.flogger.GoogleLogger; import com.google.common.flogger.LogContext; import java.io.IOException; +import java.util.Set; /** An implementation of {@link HttpRequestInitializer} with retries. */ public class RetryHttpInitializer implements HttpRequestInitializer { @@ -116,6 +117,15 @@ private static class UnsuccessfulResponseHandler implements HttpUnsuccessfulResp /** HTTP status code indicating too many requests in a given amount of time. */ private static final int HTTP_SC_TOO_MANY_REQUESTS = 429; + /** + * HTTP status code indicating that the server has decided to close the connection rather than + * continue waiting + */ + private static final int HTTP_REQUEST_TIMEOUT = 408; + + private static final Set RETRYABLE_CODES = + ImmutableSet.of(HTTP_SC_TOO_MANY_REQUESTS, HTTP_REQUEST_TIMEOUT); + // The set of response codes to log URLs for with a rate limit. private static final ImmutableSet RESPONSE_CODES_TO_LOG_WITH_RATE_LIMIT = ImmutableSet.of(HTTP_SC_TOO_MANY_REQUESTS); @@ -132,7 +142,7 @@ private static class UnsuccessfulResponseHandler implements HttpUnsuccessfulResp // of the bases cases defined by this instance. private static final HttpBackOffUnsuccessfulResponseHandler.BackOffRequired BACK_OFF_REQUIRED = response -> - response.getStatusCode() == HTTP_SC_TOO_MANY_REQUESTS + RETRYABLE_CODES.contains(response.getStatusCode()) || HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ON_SERVER_ERROR .isRequired(response);