Skip to content

Commit 8d7b28f

Browse files
authored
Spanner: fix possible thread leak in Spanner.close() (#5060)
Spanner.close() did not cleanup all threads in use A Spanner instance holds a reference to three underlying gRPC stubs: spannerStub, instanceAdminStub and databaseAdminStub. These should all have their own thread pool for gRPC calls. This was achieved by setting an executor provider on the channel provider for the stubs. The worker threads of the thread pools created by this executor provider were however not shutdown when the stubs were closed, causing thread leaks if an application would open and close multiple Spanner instances during its lifetime.
1 parent 32551b2 commit 8d7b28f

3 files changed

Lines changed: 1780 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.api.core.NanoClock;
2323
import com.google.api.gax.core.CredentialsProvider;
2424
import com.google.api.gax.core.GaxProperties;
25-
import com.google.api.gax.core.InstantiatingExecutorProvider;
2625
import com.google.api.gax.grpc.GaxGrpcProperties;
2726
import com.google.api.gax.grpc.GrpcCallContext;
2827
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
@@ -115,7 +114,6 @@
115114

116115
/** Implementation of Cloud Spanner remote calls using Gapic libraries. */
117116
public class GapicSpannerRpc implements SpannerRpc {
118-
119117
private static final PathTemplate PROJECT_NAME_TEMPLATE =
120118
PathTemplate.create("projects/{project}");
121119
private static final PathTemplate OPERATION_NAME_TEMPLATE =
@@ -190,7 +188,6 @@ public GapicSpannerRpc(SpannerOptions options) {
190188
options.getInterceptorProvider(),
191189
SpannerInterceptorProvider.createDefault()))
192190
.setHeaderProvider(mergedHeaderProvider)
193-
.setExecutorProvider(InstantiatingExecutorProvider.newBuilder().build())
194191
.build());
195192

196193
CredentialsProvider credentialsProvider =
@@ -582,6 +579,7 @@ private GrpcCallContext newCallContext(@Nullable Map<Option, ?> options, String
582579
return context.withStreamWaitTimeout(waitTimeout).withStreamIdleTimeout(idleTimeout);
583580
}
584581

582+
@Override
585583
public void shutdown() {
586584
this.spannerStub.close();
587585
this.instanceAdminStub.close();

0 commit comments

Comments
 (0)