Skip to content

Commit

Permalink
fix: update Default RetryStrategy to retry SSLException caused by Soc…
Browse files Browse the repository at this point in the history
…ketException (#1900)

Update Default RetryStrategy to retry when an SSLException is caused by a SocketException
  • Loading branch information
BenWhitehead committed Feb 15, 2023
1 parent 7b597af commit be2aba0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -24,7 +24,9 @@
import com.google.common.collect.ImmutableSet;
import com.google.gson.stream.MalformedJsonException;
import java.io.IOException;
import java.net.SocketException;
import java.util.Set;
import javax.net.ssl.SSLException;

final class DefaultStorageRetryStrategy implements StorageRetryStrategy {

Expand Down Expand Up @@ -102,7 +104,14 @@ private RetryResult shouldRetryIOException(IOException ioException) {
return RetryResult.RETRY;
} else if (ioException instanceof MalformedJsonException && idempotent) { // Gson
return RetryResult.RETRY;
} else if (BaseServiceException.isRetryable(idempotent, ioException)) {
} else if (ioException instanceof SSLException && idempotent) {
Throwable cause = ioException.getCause();
if (cause instanceof SocketException) {
SocketException se = (SocketException) cause;
return shouldRetryIOException(se);
}
}
if (BaseServiceException.isRetryable(idempotent, ioException)) {
return RetryResult.RETRY;
} else {
return RetryResult.NO_RETRY;
Expand Down
Expand Up @@ -268,6 +268,7 @@ enum ThrowableCategory {
SOCKET_EXCEPTION(C.SOCKET_EXCEPTION),
SSL_EXCEPTION(C.SSL_EXCEPTION),
SSL_EXCEPTION_CONNECTION_SHUTDOWN(C.SSL_EXCEPTION_CONNECTION_SHUTDOWN),
SSL_EXCEPTION_CONNECTION_RESET(C.SSL_EXCEPTION_CONNECTION_RESET),
SSL_HANDSHAKE_EXCEPTION(C.SSL_HANDSHAKE_EXCEPTION),
SSL_HANDSHAKE_EXCEPTION_CAUSED_BY_CERTIFICATE_EXCEPTION(
C.SSL_HANDSHAKE_EXCEPTION_CERTIFICATE_EXCEPTION),
Expand Down Expand Up @@ -305,6 +306,8 @@ enum ThrowableCategory {
STORAGE_EXCEPTION_SSL_EXCEPTION(new StorageException(C.SSL_EXCEPTION)),
STORAGE_EXCEPTION_SSL_EXCEPTION_CONNECTION_SHUTDOWN(
new StorageException(C.SSL_EXCEPTION_CONNECTION_SHUTDOWN)),
STORAGE_EXCEPTION_SSL_EXCEPTION_CONNECTION_RESET(
new StorageException(C.SSL_EXCEPTION_CONNECTION_RESET)),
STORAGE_EXCEPTION_SSL_HANDSHAKE_EXCEPTION(new StorageException(C.SSL_HANDSHAKE_EXCEPTION)),
STORAGE_EXCEPTION_SSL_HANDSHAKE_EXCEPTION_CAUSED_BY_CERTIFICATE_EXCEPTION(
new StorageException(C.SSL_HANDSHAKE_EXCEPTION_CERTIFICATE_EXCEPTION)),
Expand Down Expand Up @@ -361,6 +364,8 @@ private static final class C {
private static final SSLException SSL_EXCEPTION = new SSLException("unknown");
private static final SSLException SSL_EXCEPTION_CONNECTION_SHUTDOWN =
new SSLException("Connection has been shutdown: asdf");
private static final SSLException SSL_EXCEPTION_CONNECTION_RESET =
new SSLException("Connection reset", new SocketException("Connection reset"));
private static final SSLHandshakeException SSL_HANDSHAKE_EXCEPTION =
newSslHandshakeExceptionWithCause(new SSLProtocolException(DEFAULT_MESSAGE));
private static final SSLHandshakeException SSL_HANDSHAKE_EXCEPTION_CERTIFICATE_EXCEPTION =
Expand Down Expand Up @@ -614,6 +619,16 @@ private static ImmutableList<Case> getAllCases() {
HandlerCategory.NONIDEMPOTENT,
ExpectRetry.NO,
Behavior.SAME),
new Case(
ThrowableCategory.SSL_EXCEPTION_CONNECTION_RESET,
HandlerCategory.IDEMPOTENT,
ExpectRetry.YES,
Behavior.DEFAULT_MORE_PERMISSIBLE),
new Case(
ThrowableCategory.SSL_EXCEPTION_CONNECTION_RESET,
HandlerCategory.NONIDEMPOTENT,
ExpectRetry.NO,
Behavior.SAME),
new Case(
ThrowableCategory.SSL_HANDSHAKE_EXCEPTION,
HandlerCategory.IDEMPOTENT,
Expand Down Expand Up @@ -884,6 +899,16 @@ private static ImmutableList<Case> getAllCases() {
HandlerCategory.NONIDEMPOTENT,
ExpectRetry.NO,
Behavior.DEFAULT_MORE_STRICT),
new Case(
ThrowableCategory.STORAGE_EXCEPTION_SSL_EXCEPTION_CONNECTION_RESET,
HandlerCategory.IDEMPOTENT,
ExpectRetry.YES,
Behavior.DEFAULT_MORE_PERMISSIBLE),
new Case(
ThrowableCategory.STORAGE_EXCEPTION_SSL_EXCEPTION_CONNECTION_RESET,
HandlerCategory.NONIDEMPOTENT,
ExpectRetry.NO,
Behavior.SAME),
new Case(
ThrowableCategory.STORAGE_EXCEPTION_SSL_HANDSHAKE_EXCEPTION,
HandlerCategory.IDEMPOTENT,
Expand Down

0 comments on commit be2aba0

Please sign in to comment.