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: retry INTERNAL retriable auth errors #2239

Merged
merged 4 commits into from
May 21, 2024
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 @@ -77,12 +77,20 @@ protected void onCompleteImpl() {
private Throwable convertException(Throwable t) {
// Long lived connections sometimes are disconnected via an RST frame or a goaway. These errors
// are transient and should be retried.
if (isRstStreamError(t) || isGoAway(t)) {
if (isRstStreamError(t) || isGoAway(t) || isRetriableAuthError(t)) {
return new InternalException(t, ((InternalException) t).getStatusCode(), true);
}
return t;
}

private boolean isRetriableAuthError(Throwable t) {
if (t instanceof InternalException && t.getMessage() != null) {
String error = t.getMessage();
return error.contains("Authentication backend internal server error. Please retry");
}
return false;
}

private boolean isRstStreamError(Throwable t) {
if (t instanceof InternalException && t.getMessage() != null) {
String error = t.getMessage().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ public void rstStreamExceptionConvertedToRetryableTest() {
assertTrue(actualException.isRetryable());
}

@Test
public void retriableAuthExceptionConvertedToRetryableTest() {
ApiException originalException =
new InternalException(
new StatusRuntimeException(
Status.INTERNAL.withDescription(
"Authentication backend internal server error. Please retry")),
GrpcStatusCode.of(Status.Code.INTERNAL),
false);
assertFalse(originalException.isRetryable());
SettableExceptionCallable<String, String> settableExceptionCallable =
new SettableExceptionCallable<>(originalException);
ConvertExceptionCallable<String, String> convertStreamExceptionCallable =
new ConvertExceptionCallable<>(settableExceptionCallable);

Throwable actualError = null;
try {
convertStreamExceptionCallable.all().call("fake-request");
} catch (Throwable t) {
actualError = t;
}
assert actualError instanceof InternalException;
InternalException actualException = (InternalException) actualError;
assertTrue(actualException.isRetryable());
}

private static final class SettableExceptionCallable<RequestT, ResponseT>
extends ServerStreamingCallable<RequestT, ResponseT> {
private final Throwable throwable;
Expand Down
Loading