Skip to content

Commit 7cc4e86

Browse files
committed
chore: make internal auth backend errors retryable
Spanner occasionally returns INTERNAL errors regarding the auth backend server. These errors should be regarded as retryable.
1 parent 56938e7 commit 7cc4e86

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/IsRetryableInternalError.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,25 @@
1818

1919
import com.google.api.gax.rpc.InternalException;
2020
import com.google.common.base.Predicate;
21+
import com.google.common.collect.ImmutableList;
2122
import io.grpc.Status;
2223
import io.grpc.StatusRuntimeException;
2324

2425
public class IsRetryableInternalError implements Predicate<Throwable> {
2526

26-
private static final String HTTP2_ERROR_MESSAGE = "HTTP/2 error code: INTERNAL_ERROR";
27-
private static final String CONNECTION_CLOSED_ERROR_MESSAGE =
28-
"Connection closed with unknown cause";
29-
private static final String EOS_ERROR_MESSAGE =
30-
"Received unexpected EOS on DATA frame from server";
31-
32-
private static final String RST_STREAM_ERROR_MESSAGE = "stream terminated by RST_STREAM";
27+
private static final ImmutableList<String> RETRYABLE_ERROR_MESSAGES =
28+
ImmutableList.of(
29+
"HTTP/2 error code: INTERNAL_ERROR",
30+
"Connection closed with unknown cause",
31+
"Received unexpected EOS on DATA frame from server",
32+
"stream terminated by RST_STREAM",
33+
"Authentication backend internal server error. Please retry.");
3334

3435
@Override
3536
public boolean apply(Throwable cause) {
3637
if (isInternalError(cause)) {
37-
if (cause.getMessage().contains(HTTP2_ERROR_MESSAGE)) {
38-
return true;
39-
} else if (cause.getMessage().contains(CONNECTION_CLOSED_ERROR_MESSAGE)) {
40-
return true;
41-
} else if (cause.getMessage().contains(EOS_ERROR_MESSAGE)) {
42-
return true;
43-
} else if (cause.getMessage().contains(RST_STREAM_ERROR_MESSAGE)) {
44-
return true;
45-
}
38+
return RETRYABLE_ERROR_MESSAGES.stream()
39+
.anyMatch(message -> cause.getMessage().contains(message));
4640
}
4741
return false;
4842
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/IsRetryableInternalErrorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ public void rstStreamInternalExceptionIsRetryable() {
127127
assertTrue(predicate.apply(e));
128128
}
129129

130+
@Test
131+
public void testAuthenticationBackendInternalServerErrorIsRetryable() {
132+
final StatusRuntimeException exception =
133+
new StatusRuntimeException(
134+
Status.fromCode(Code.INTERNAL)
135+
.withDescription(
136+
"INTERNAL: Authentication backend internal server error. Please retry."));
137+
138+
assertTrue(predicate.apply(exception));
139+
}
140+
130141
@Test
131142
public void genericInternalExceptionIsNotRetryable() {
132143
final InternalException e =

0 commit comments

Comments
 (0)