GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: Retry "received rst stream" by mutianf · Pull Request #586 · googleapis/java-bigtable

This repository was archived by the owner on Aug 30, 2026. It is now read-only.

fix: Retry "received rst stream" #586

Merged
mutianf merged 2 commits into googleapis:master from mutianf:retry_rst_stream
Jan 27, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix: Retry "received rst stream" #586

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
758a5f2
fix: Retry "received rst stream"
mutianf Jan 5, 2021
246f389
Check if exception is InternalException instead of using fromThrowable
mutianf Jan 20, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

9 changes: 8 additions & 1 deletion 9 ...d-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsRetryingCallable;
import com.google.cloud.bigtable.data.v2.stub.readrows.FilterMarkerRowsCallable;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsConvertExceptionCallable;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsResumptionStrategy;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsRetryCompletedCallable;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable;
Expand Down Expand Up @@ -345,8 +346,14 @@ public Map<String, String> extract(ReadRowsRequest readRowsRequest) {
.build(),
readRowsSettings.getRetryableCodes());

// Sometimes ReadRows connections are disconnected via an RST frame. This error is transient and
// should be treated similar to UNAVAILABLE. However, this exception has an INTERNAL error code
// which by default is not retryable. Convert the exception so it can be retried in the client.
ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> convertException =
new ReadRowsConvertExceptionCallable<>(base);

ServerStreamingCallable<ReadRowsRequest, RowT> merging =
new RowMergingCallable<>(base, rowAdapter);
new RowMergingCallable<>(convertException, rowAdapter);

// Copy settings for the middle ReadRowsRequest -> RowT callable (as opposed to the inner
// ReadRowsRequest -> ReadRowsResponse callable).
Expand Down
87 changes: 87 additions & 0 deletions 87 ...ava/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsConvertExceptionCallable.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigtable.data.v2.stub.readrows;

import com.google.api.core.InternalApi;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.InternalException;
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.StreamController;

/**
* This callable converts the "Received rst stream" exception into a retryable {@link ApiException}.
*/
@InternalApi
public final class ReadRowsConvertExceptionCallable<ReadRowsRequest, RowT>
extends ServerStreamingCallable<ReadRowsRequest, RowT> {

private final ServerStreamingCallable<ReadRowsRequest, RowT> innerCallable;

public ReadRowsConvertExceptionCallable(
ServerStreamingCallable<ReadRowsRequest, RowT> innerCallable) {
this.innerCallable = innerCallable;
}

@Override
public void call(
ReadRowsRequest request, ResponseObserver<RowT> responseObserver, ApiCallContext context) {
ReadRowsConvertExceptionResponseObserver<RowT> observer =
new ReadRowsConvertExceptionResponseObserver<>(responseObserver);
innerCallable.call(request, observer, context);
}

private class ReadRowsConvertExceptionResponseObserver<RowT> implements ResponseObserver<RowT> {

private final ResponseObserver<RowT> outerObserver;

ReadRowsConvertExceptionResponseObserver(ResponseObserver<RowT> outerObserver) {
this.outerObserver = outerObserver;
}

@Override
public void onStart(StreamController controller) {
outerObserver.onStart(controller);
}

@Override
public void onResponse(RowT response) {
outerObserver.onResponse(response);
}

@Override
public void onError(Throwable t) {
outerObserver.onError(convertException(t));
}

@Override
public void onComplete() {
outerObserver.onComplete();
}
}

private Throwable convertException(Throwable t) {
// Long lived connections sometimes are disconnected via an RST frame. This error is
// transient and should be retried.
if (t instanceof InternalException) {
if (t.getMessage() != null && t.getMessage().contains("Received Rst stream")) {
return new InternalException(t, ((InternalException) t).getStatusCode(), true);
}
}
return t;
}
}
37 changes: 37 additions & 0 deletions 37 ...able/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
package com.google.cloud.bigtable.data.v2.stub.readrows;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.api.gax.rpc.InternalException;
import com.google.api.gax.rpc.ServerStream;
import com.google.bigtable.v2.BigtableGrpc;
import com.google.bigtable.v2.ReadRowsRequest;
Expand All @@ -39,6 +42,7 @@
import com.google.protobuf.StringValue;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcServerRule;
import java.io.IOException;
Expand Down Expand Up @@ -260,6 +264,30 @@ public void retryWithLastScannedKeyTest() {
Truth.assertThat(actualResults).containsExactly("r7").inOrder();
}

@Test
public void retryRstStreamExceptionTest() {
ApiException exception =
new InternalException(
new StatusRuntimeException(
Status.INTERNAL.withDescription(
"HTTP/2 error code: INTERNAL_ERROR\nReceived Rst stream")),
GrpcStatusCode.of(Code.INTERNAL),
false);
service.expectations.add(
RpcExpectation.create()
.expectRequest("k1")
.expectRequest(Range.closedOpen("r1", "r3"))
.respondWithException(Code.INTERNAL, exception));
service.expectations.add(
RpcExpectation.create()
.expectRequest("k1")
.expectRequest(Range.closedOpen("r1", "r3"))
.respondWith("k1", "r1", "r2"));

List<String> actualResults = getResults(Query.create(TABLE_ID).rowKey("k1").range("r1", "r3"));
Truth.assertThat(actualResults).containsExactly("k1", "r1", "r2").inOrder();
}

private List<String> getResults(Query query) {
ServerStream<Row> actualRows = client.readRows(query);
List<String> actualValues = Lists.newArrayList();
Expand Down Expand Up @@ -292,6 +320,8 @@ public void readRows(
}
if (expectedRpc.statusCode.toStatus().isOk()) {
responseObserver.onCompleted();
} else if (expectedRpc.exception != null) {
responseObserver.onError(expectedRpc.exception);
} else {
responseObserver.onError(expectedRpc.statusCode.toStatus().asRuntimeException());
}
Expand All @@ -301,6 +331,7 @@ public void readRows(
private static class RpcExpectation {
ReadRowsRequest.Builder requestBuilder;
Status.Code statusCode;
ApiException exception;
List<ReadRowsResponse> responses;

private RpcExpectation() {
Expand Down Expand Up @@ -370,6 +401,12 @@ RpcExpectation respondWithStatus(Status.Code code) {
return this;
}

RpcExpectation respondWithException(Status.Code code, ApiException exception) {
this.statusCode = code;
this.exception = exception;
return this;
}

RpcExpectation respondWith(String... responses) {
for (String response : responses) {
this.responses.add(
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.