diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageRetryStrategy.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageRetryStrategy.java index cf85b7400d..b9a8df0b52 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageRetryStrategy.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultStorageRetryStrategy.java @@ -26,6 +26,7 @@ import com.google.gson.stream.MalformedJsonException; import java.io.IOException; import java.net.SocketException; +import java.net.UnknownHostException; import java.util.Set; import javax.net.ssl.SSLException; @@ -114,6 +115,8 @@ private RetryResult shouldRetryIOException(IOException ioException) { SocketException se = (SocketException) cause; return shouldRetryIOException(se); } + } else if (ioException instanceof UnknownHostException && idempotent) { + return RetryResult.RETRY; } if (BaseServiceException.isRetryable(idempotent, ioException)) { return RetryResult.RETRY; diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/DefaultRetryHandlingBehaviorTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/DefaultRetryHandlingBehaviorTest.java index f1c37b09d4..0f90c7524f 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/DefaultRetryHandlingBehaviorTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/DefaultRetryHandlingBehaviorTest.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.security.cert.CertificateException; import java.util.Arrays; import java.util.Collection; @@ -342,6 +343,7 @@ enum ThrowableCategory { IO_EXCEPTION(new IOException("no retry")), AUTH_RETRYABLE_TRUE(new RetryableException(true)), AUTH_RETRYABLE_FALSE(new RetryableException(false)), + UNKNOWN_HOST_EXCEPTION(C.UNKNOWN_HOST_EXCEPTION), ; private final Throwable throwable; @@ -415,6 +417,8 @@ private static final class C { private static final MalformedJsonException GSON_MALFORMED_EXCEPTION = new MalformedJsonException("parse-exception"); private static final IOException IO_PREMATURE_EOF = new IOException("Premature EOF"); + private static final UnknownHostException UNKNOWN_HOST_EXCEPTION = + new UnknownHostException("fake.fake"); private static HttpResponseException newHttpResponseException( int httpStatusCode, String name) { @@ -1065,6 +1069,16 @@ private static ImmutableList getAllCases() { ThrowableCategory.AUTH_RETRYABLE_FALSE, HandlerCategory.NONIDEMPOTENT, ExpectRetry.NO, + Behavior.SAME), + new Case( + ThrowableCategory.UNKNOWN_HOST_EXCEPTION, + HandlerCategory.IDEMPOTENT, + ExpectRetry.YES, + Behavior.DEFAULT_MORE_PERMISSIBLE), + new Case( + ThrowableCategory.UNKNOWN_HOST_EXCEPTION, + HandlerCategory.NONIDEMPOTENT, + ExpectRetry.NO, Behavior.SAME)) .build(); }