Skip to content

Commit

Permalink
fix: add UnknownHostException to set of retriable exception (#2651)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWhitehead authored Jul 31, 2024
1 parent d0e9af1 commit 18de9fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1065,6 +1069,16 @@ private static ImmutableList<Case> 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();
}
Expand Down

0 comments on commit 18de9fc

Please sign in to comment.