Skip to content

Commit a2d9a33

Browse files
authored
fix: partitionedDml stub was not closed (#213)
The PartitionedDML stub was not closed when Spanner was closed. In addition, Spanner did not wait for the channels to actually close, causing some test cases to (sometimes) log a warning that the channel had not been closed.
1 parent 5fa82b9 commit a2d9a33

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ private synchronized void shutdown() {
191191
executor.shutdown();
192192
}
193193
}
194+
195+
private void awaitTermination() throws InterruptedException {
196+
for (ScheduledExecutorService executor : executors) {
197+
executor.awaitTermination(10L, TimeUnit.SECONDS);
198+
}
199+
}
194200
}
195201

196202
private static final PathTemplate PROJECT_NAME_TEMPLATE =
@@ -1230,10 +1236,22 @@ GrpcCallContext newCallContext(@Nullable Map<Option, ?> options, String resource
12301236
public void shutdown() {
12311237
this.rpcIsClosed = true;
12321238
this.spannerStub.close();
1239+
this.partitionedDmlStub.close();
12331240
this.instanceAdminStub.close();
12341241
this.databaseAdminStub.close();
12351242
this.spannerWatchdog.shutdown();
12361243
this.executorProvider.shutdown();
1244+
1245+
try {
1246+
this.spannerStub.awaitTermination(10L, TimeUnit.SECONDS);
1247+
this.partitionedDmlStub.awaitTermination(10L, TimeUnit.SECONDS);
1248+
this.instanceAdminStub.awaitTermination(10L, TimeUnit.SECONDS);
1249+
this.databaseAdminStub.awaitTermination(10L, TimeUnit.SECONDS);
1250+
this.spannerWatchdog.awaitTermination(10L, TimeUnit.SECONDS);
1251+
this.executorProvider.awaitTermination();
1252+
} catch (InterruptedException e) {
1253+
throw SpannerExceptionFactory.propagateInterrupt(e);
1254+
}
12371255
}
12381256

12391257
@Override

0 commit comments

Comments
 (0)