Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update Default RetryStrategy to retry SSLException caused by SocketException #1900

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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