Skip to content

Commit 782894e

Browse files
fix: also shutdown the stream connection in case the timeout exception is
triggered.
1 parent cc9fdfd commit 782894e

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ConnectionWorker.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void run() {
353353
} finally {
354354
lock.unlock();
355355
}
356-
cleanupInflightRequests();
356+
cleanup(/* waitForDone= */ false);
357357
});
358358
this.appendThread.start();
359359
}
@@ -812,7 +812,10 @@ private void appendLoop() {
812812
this.streamConnection.send(originalRequestBuilder.build());
813813
}
814814
}
815+
cleanup(/* waitForDone= */true);
816+
}
815817

818+
private void cleanup(boolean waitForDone) {
816819
log.info(
817820
"Cleanup starts. Stream: "
818821
+ streamName
@@ -828,7 +831,9 @@ private void appendLoop() {
828831
// We can close the stream connection and handle the remaining inflight requests.
829832
if (streamConnection != null) {
830833
this.streamConnection.close();
831-
waitForDoneCallback(3, TimeUnit.MINUTES);
834+
if (waitForDone) {
835+
waitForDoneCallback(3, TimeUnit.MINUTES);
836+
}
832837
}
833838

834839
// At this point, there cannot be more callback. It is safe to clean up all inflight requests.

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@ public void testThrowExceptionWhileWithinAppendLoop_MaxWaitTimeExceed() throws E
650650
null,
651651
client.getSettings(),
652652
retrySettings);
653-
testBigQueryWrite.setResponseSleep(org.threeten.bp.Duration.ofSeconds(3));
653+
testBigQueryWrite.setResponseSleep(org.threeten.bp.Duration.ofSeconds(2));
654654

655-
long appendCount = 10;
655+
long appendCount = 2;
656656
for (int i = 0; i < appendCount; i++) {
657657
testBigQueryWrite.addResponse(createAppendResponse(i));
658658
}
@@ -691,6 +691,8 @@ public void testThrowExceptionWhileWithinAppendLoop_MaxWaitTimeExceed() throws E
691691
100)
692692
.get());
693693
assertThat(ex.getCause()).hasMessageThat().contains("Request has waited in inflight queue");
694+
connectionWorker.close();
695+
assertTrue(connectionWorker.isUserClosed());
694696
}
695697

696698
@Test

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
import com.google.cloud.bigquery.storage.v1.*;
3333
import com.google.cloud.bigquery.storage.v1.AppendRowsRequest.MissingValueInterpretation;
3434
import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError;
35+
import com.google.cloud.bigquery.storage.v1.Exceptions.MaximumRequestCallbackWaitTimeExceededException;
3536
import com.google.cloud.bigquery.storage.v1.Exceptions.OffsetAlreadyExists;
3637
import com.google.cloud.bigquery.storage.v1.Exceptions.OffsetOutOfRange;
3738
import com.google.cloud.bigquery.storage.v1.Exceptions.SchemaMismatchedException;
3839
import com.google.cloud.bigquery.storage.v1.Exceptions.StreamFinalizedException;
40+
import com.google.cloud.bigquery.storage.v1.Exceptions.StreamWriterClosedException;
3941
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
4042
import com.google.common.collect.ImmutableList;
4143
import com.google.protobuf.ByteString;
@@ -49,6 +51,7 @@
4951
import java.math.BigDecimal;
5052
import java.sql.Timestamp;
5153
import java.text.ParseException;
54+
import java.time.Duration;
5255
import java.time.Instant;
5356
import java.time.ZoneId;
5457
import java.time.temporal.ChronoUnit;

0 commit comments

Comments
 (0)