Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cf752ea

Browse files
authoredFeb 7, 2023
fix: Modify ConvertExceptionCallable to retry on Goaway (#1588)
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).
1 parent 78b32b3 commit cf752ea

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed
 

‎google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/ConvertExceptionCallable.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.api.gax.rpc.ResponseObserver;
2222
import com.google.api.gax.rpc.ServerStreamingCallable;
2323
import com.google.api.gax.rpc.StreamController;
24+
import com.google.common.base.Throwables;
2425

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

7576
private Throwable convertException(Throwable t) {
76-
// Long lived connections sometimes are disconnected via an RST frame. This error is
77-
// transient and should be retried.
77+
// Long lived connections sometimes are disconnected via an RST frame or a goaway. These errors
78+
// are transient and should be retried.
79+
if (isRstStreamError(t) || isGoAway(t)) {
80+
return new InternalException(t, ((InternalException) t).getStatusCode(), true);
81+
}
82+
return t;
83+
}
84+
85+
private boolean isRstStreamError(Throwable t) {
7886
if (t instanceof InternalException && t.getMessage() != null) {
7987
String error = t.getMessage().toLowerCase();
80-
if (error.contains("rst_stream") || error.contains("rst stream")) {
81-
return new InternalException(t, ((InternalException) t).getStatusCode(), true);
82-
}
88+
return error.contains("rst_stream") || error.contains("rst stream");
8389
}
84-
return t;
90+
return false;
91+
}
92+
93+
private boolean isGoAway(Throwable t) {
94+
if (t instanceof InternalException) {
95+
Throwable rootCause = Throwables.getRootCause(t);
96+
String rootCauseMessage = rootCause.getMessage();
97+
return rootCauseMessage != null
98+
&& rootCauseMessage.contains("Stream closed before write could take place");
99+
}
100+
return false;
85101
}
86102
}

0 commit comments

Comments
 (0)
Failed to load comments.