googleapis / java-spanner Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: close executor when closing pool #501
Conversation
"There is/are " | ||
+ keysStillInUse.size() | ||
+ " connection(s) still open. Close all connections before calling closeSpanner()"); | ||
} finally { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only real change here is the addition of the finally
block, but GitHub thinks there is a lot more changed because of the changed indentation and formatting.
cc @jjfox15 |
Codecov Report
@@ Coverage Diff @@
## master #501 +/- ##
=========================================
Coverage ? 82.26%
Complexity ? 2395
=========================================
Files ? 138
Lines ? 13414
Branches ? 1240
=========================================
Hits ? 11035
Misses ? 1883
Partials ? 496
Continue to review full report at Codecov.
|
+ " connection(s) still open. Close all connections before calling closeSpanner()"); | ||
} finally { | ||
if (closerService != null) { | ||
closerService.shutdown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this throw an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, no. It does not declare any checked exceptions, and it also does not wait until it has actually been shutdown, so the chance that anything goes wrong is relatively low.
The method can be invoked in two ways:
- If a client application calls
SpannerPool#closeSpannerPool()
to explicitly close the pool. Any exception fromcloserService.shutdown()
would in that case be propagated to the client application. Considering the fact that it would not be a checked exception, I would say that that is a reasonable thing to do, as it might indicate a problem somewhere, for example linked to the state of the client application at that moment. - It is called from the shutdown hook that closes the pool automatically when the application terminates. The shutdown hook catches and ignores any errors, as any errors at that moment are (probably) not something that a client application could do anything with. The alternative would be to bubble it up, which would cause the JVM (by default) to print the error to
System.err
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that is fine, I was just worried that we could bubble up exceptions that we previously did not.
Shutdown the executor that maintains the pool when the pool is closing.