Skip to content

Commit

Permalink
fix: Modify ConvertExceptionCallable to retry on Goaway (#1588)
Browse files Browse the repository at this point in the history
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the [samples format](
https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
  • Loading branch information
jackdingilian committed Feb 7, 2023
1 parent 78b32b3 commit cf752ea
Showing 1 changed file with 22 additions and 6 deletions.
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;
}
}

0 comments on commit cf752ea

Please sign in to comment.