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
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.5.0')
implementation platform('com.google.cloud:libraries-bom:26.6.0')

implementation 'com.google.cloud:google-cloud-bigtable'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-bigtable:2.18.3'
implementation 'com.google.cloud:google-cloud-bigtable:2.18.4'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.18.3"
libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.18.4"
```

## Authentication
Expand Down
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;
}
}