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: Modify ConvertExceptionCallable to retry on Goaway #1588

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Changes from 1 commit
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 @@ -21,6 +21,7 @@
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.StreamController;
import com.google.common.base.Throwables;

/**
* This callable converts the "Received rst stream" exception into a retryable {@link ApiException}.
Expand Down Expand Up @@ -73,14 +74,29 @@ protected void onCompleteImpl() {
}

private Throwable convertException(Throwable t) {
// Long lived connections sometimes are disconnected via an RST frame. This error is
// transient and should be retried.
// 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)) {
return new InternalException(t, ((InternalException) t).getStatusCode(), true);
}
return t;
}

private boolean isRstStreamError(Throwable t) {
if (t instanceof InternalException && t.getMessage() != null) {
String error = t.getMessage().toLowerCase();
if (error.contains("rst_stream") || error.contains("rst stream")) {
return new InternalException(t, ((InternalException) t).getStatusCode(), true);
}
return error.contains("rst_stream") || error.contains("rst stream");
}
return t;
return false;
}

private boolean isGoAway(Throwable t) {
if (t instanceof InternalException) {
Throwable rootCause = Throwables.getRootCause(t);
String rootCauseMessage = rootCause.getMessage();
return rootCauseMessage != null
&& rootCauseMessage.contains("Stream closed before write could take place");
}
return false;
}
}