Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 95b40b5

Browse files
authored
Merge 441b1aa into 004c5d7
2 parents 004c5d7 + 441b1aa commit 95b40b5

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.cloud.grpc.GrpcTransportOptions;
2626
import com.google.cloud.spanner.SessionClient.SessionId;
2727
import com.google.cloud.spanner.SpannerOptions.CloseableExecutorProvider;
28+
import com.google.cloud.spanner.spi.v1.GapicSpannerRpc;
2829
import com.google.cloud.spanner.spi.v1.SpannerRpc;
2930
import com.google.cloud.spanner.spi.v1.SpannerRpc.Paginated;
3031
import com.google.common.annotations.VisibleForTesting;
@@ -269,7 +270,11 @@ void close(long timeout, TimeUnit unit) {
269270
sessionClients.clear();
270271
asyncExecutorProvider.close();
271272
try {
272-
gapicRpc.shutdown();
273+
if (timeout == Long.MAX_VALUE || !(gapicRpc instanceof GapicSpannerRpc)) {
274+
gapicRpc.shutdown();
275+
} else {
276+
((GapicSpannerRpc) gapicRpc).shutdownNow();
277+
}
273278
} catch (RuntimeException e) {
274279
logger.log(Level.WARNING, "Failed to close channels", e);
275280
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,22 @@ public void shutdown() {
17181718
}
17191719
}
17201720

1721+
public void shutdownNow() {
1722+
this.rpcIsClosed = true;
1723+
this.spannerStub.close();
1724+
this.partitionedDmlStub.close();
1725+
this.instanceAdminStub.close();
1726+
this.databaseAdminStub.close();
1727+
this.spannerWatchdog.shutdown();
1728+
this.executorProvider.shutdown();
1729+
1730+
this.spannerStub.shutdownNow();
1731+
this.partitionedDmlStub.shutdownNow();
1732+
this.instanceAdminStub.shutdownNow();
1733+
this.databaseAdminStub.shutdownNow();
1734+
this.spannerWatchdog.shutdownNow();
1735+
}
1736+
17211737
@Override
17221738
public boolean isClosed() {
17231739
return rpcIsClosed;

google-cloud-spanner/src/test/java/com/google/cloud/spanner/BackendExhaustedTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ public void setUp() throws Exception {
136136
SessionPoolOptions.newBuilder()
137137
.setMinSessions(executor.getCorePoolSize())
138138
.setMaxSessions(executor.getCorePoolSize() * 3)
139-
.setWriteSessionsFraction(0.0f)
140139
.build())
141140
.build();
142141
executorFactory.release(executor);
@@ -159,7 +158,7 @@ public void tearDown() {
159158
// This test case force-closes the Spanner instance as it would otherwise wait
160159
// forever on the BatchCreateSessions requests that are 'stuck'.
161160
try {
162-
((SpannerImpl) spanner).close(100L, TimeUnit.MILLISECONDS);
161+
((SpannerImpl) spanner).close(10L, TimeUnit.MILLISECONDS);
163162
} catch (SpannerException e) {
164163
// ignore any errors during close as they are expected.
165164
}

0 commit comments

Comments
 (0)