-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: More robust STREAM_RST logic (#1102)
* fix: more robust STREAM_RST logic * Update google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/Errors.java Co-authored-by: Stephanie Wang <stephaniewang526@users.noreply.github.com> * Update google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/util/ErrorsTest.java Co-authored-by: Stephanie Wang <stephaniewang526@users.noreply.github.com> Co-authored-by: Stephanie Wang <stephaniewang526@users.noreply.github.com>
- Loading branch information
1 parent
b2e3489
commit dd67534
Showing
5 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...le-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/Errors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.bigquery.storage.util; | ||
|
||
import io.grpc.Status; | ||
|
||
/** Static utility methods for working with Errors returned from the service. */ | ||
public class Errors { | ||
private Errors() {}; | ||
|
||
/** | ||
* Returns true iff the Status indicates and internal error that is retryable. | ||
* | ||
* <p>Generally, internal errors are not considered retryable, however there are certain transient | ||
* network issues that appear as internal but are in fact retryable. | ||
*/ | ||
public static boolean isRetryableInternalStatus(Status status) { | ||
String description = status.getDescription(); | ||
return status.getCode() == Status.Code.INTERNAL | ||
&& description != null | ||
&& (description.contains("Received unexpected EOS on DATA frame from server") | ||
|| description.contains(" Rst ") | ||
|| description.contains("RST_STREAM") | ||
|| description.contains("Connection closed with unknown cause") | ||
|| description.contains("HTTP/2 error code: INTERNAL_ERROR")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...loud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/util/ErrorsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.bigquery.storage.util; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import io.grpc.Status; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class ErrorsTest { | ||
|
||
@Test | ||
public void testRetryableInternalForRstErrors() { | ||
assertTrue( | ||
Errors.isRetryableInternalStatus( | ||
Status.INTERNAL.withDescription( | ||
"HTTP/2 error code: INTERNAL_ERROR\nReceived Rst stream"))); | ||
assertTrue( | ||
Errors.isRetryableInternalStatus( | ||
Status.INTERNAL.withDescription( | ||
"RST_STREAM closed stream. HTTP/2 error code: INTERNAL_ERROR"))); | ||
} | ||
|
||
@Test | ||
public void testNonRetryableInternalError() { | ||
assertFalse(Errors.isRetryableInternalStatus(Status.INTERNAL)); | ||
assertFalse(Errors.isRetryableInternalStatus(Status.INTERNAL.withDescription("Server error."))); | ||
} | ||
|
||
@Test | ||
public void testNonRetryableOtherError() { | ||
assertFalse( | ||
Errors.isRetryableInternalStatus( | ||
Status.DATA_LOSS.withDescription( | ||
"RST_STREAM closed stream. HTTP/2 error code: INTERNAL_ERROR"))); | ||
} | ||
} |