Skip to content

Commit

Permalink
fix: retry INTERNAL retriable auth errors (#2239)
Browse files Browse the repository at this point in the history
* fix: retry INTERNAL retriable auth errors

Change-Id: I3939a89d40ecd4304bccaf0340fe169d6a083712

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
igorbernstein2 and gcf-owl-bot[bot] committed May 21, 2024
1 parent d1bceb0 commit 4cdb6da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit 4cdb6da

Please sign in to comment.