Spanner: fix possible thread leak in Spanner.close()#5060
Merged
olavloite merged 7 commits intogoogleapis:masterfrom May 6, 2019
Merged
Spanner: fix possible thread leak in Spanner.close()#5060olavloite merged 7 commits intogoogleapis:masterfrom
olavloite merged 7 commits intogoogleapis:masterfrom
Conversation
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.
Codecov Report
@@ Coverage Diff @@
## master #5060 +/- ##
============================================
- Coverage 50.38% 50.07% -0.31%
+ Complexity 23735 22379 -1356
============================================
Files 2248 2248
Lines 226478 221803 -4675
Branches 24954 24836 -118
============================================
- Hits 114113 111075 -3038
+ Misses 103772 103016 -756
+ Partials 8593 7712 -881
Continue to review full report at Codecov.
|
The custom ThreadFactory is not necessary for this fix. Setting an executor on the stub settings is not necessary, as the default for these settings are all an InstantiatingExecutorProvider.
kolea2
reviewed
May 6, 2019
|
|
||
| /** Implementation of Cloud Spanner remote calls using Gapic libraries. */ | ||
| public class GapicSpannerRpc implements SpannerRpc { | ||
| // Thread factory to use to create our worker threads |
Contributor
There was a problem hiding this comment.
minor - think you can remove this comment
Contributor
Author
There was a problem hiding this comment.
You're right, this is no longer valid.
kolea2
reviewed
May 6, 2019
| options.getInterceptorProvider(), | ||
| SpannerInterceptorProvider.createDefault())) | ||
| .setHeaderProvider(mergedHeaderProvider) | ||
| .setExecutorProvider(InstantiatingExecutorProvider.newBuilder().build()) |
Contributor
There was a problem hiding this comment.
Since each underlying grpc stub gets set this executor provider by default, is it correct that each stub will not use a shared executor for its transport channel (the one potential problem listed in the issue with this change)?
kolea2
approved these changes
May 6, 2019
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Fixes #5059