Skip to content
Permalink
Browse files
fix: close executor when closing pool (#501)
  • Loading branch information
olavloite committed Oct 9, 2020
1 parent 62fa39a commit 208674632b20b37f51b828c1c4cc76c91154952b
Showing with 24 additions and 16 deletions.
  1. +24 −16 google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/SpannerPool.java
@@ -398,26 +398,34 @@ void checkAndCloseSpanners(CheckAndCloseSpannersMode mode) {
keysStillInUse.add(entry.getKey());
}
}
if (keysStillInUse.isEmpty() || mode == CheckAndCloseSpannersMode.WARN) {
if (!keysStillInUse.isEmpty()) {
try {
if (keysStillInUse.isEmpty() || mode == CheckAndCloseSpannersMode.WARN) {
if (!keysStillInUse.isEmpty()) {
logLeakedConnections(keysStillInUse);
logger.log(
Level.WARNING,
"There is/are "
+ keysStillInUse.size()
+ " connection(s) still open."
+ " Close all connections before stopping the application");
}
// Force close all Spanner instances by passing in a value that will always be less than
// the
// difference between the current time and the close time of a connection.
closeUnusedSpanners(Long.MIN_VALUE);
} else {
logLeakedConnections(keysStillInUse);
logger.log(
Level.WARNING,
throw SpannerExceptionFactory.newSpannerException(
ErrorCode.FAILED_PRECONDITION,
"There is/are "
+ keysStillInUse.size()
+ " connection(s) still open."
+ " Close all connections before stopping the application");
+ " connection(s) still open. Close all connections before calling closeSpanner()");
}
// Force close all Spanner instances by passing in a value that will always be less than the
// difference between the current time and the close time of a connection.
closeUnusedSpanners(Long.MIN_VALUE);
} else {
logLeakedConnections(keysStillInUse);
throw SpannerExceptionFactory.newSpannerException(
ErrorCode.FAILED_PRECONDITION,
"There is/are "
+ keysStillInUse.size()
+ " connection(s) still open. Close all connections before calling closeSpanner()");
} finally {
if (closerService != null) {
closerService.shutdown();
}
initialized = false;
}
}
}

0 comments on commit 2086746

Please sign in to comment.