Skip to content

Commit 636774a

Browse files
committed
Use heartbeatLock.lock(); around internal shutdownPool() method
To protect against a possible race condition between a shutdown hook invocation and application code invocation.
1 parent 2c536a7 commit 636774a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

ebean-datasource/src/main/java/io/ebean/datasource/pool/ConnectionPool.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -656,17 +656,22 @@ public void offline() {
656656
}
657657

658658
private void shutdownPool(boolean fullShutdown, boolean fromHook) {
659-
stopHeartBeatIfRunning();
660-
PoolStatus status = queue.shutdown(fullShutdown);
661-
dataSourceUp.set(false);
662-
if (fullShutdown) {
663-
shutdownExecutor();
664-
}
665-
if (fromHook) {
666-
Log.info("DataSource [{0}] shutdown on JVM exit {1} psc[hit:{2} miss:{3} put:{4} rem:{5}]", name, status, pscHit, pscMiss, pscPut, pscRem);
667-
} else {
668-
Log.info("DataSource [{0}] shutdown {1} psc[hit:{2} miss:{3} put:{4} rem:{5}]", name, status, pscHit, pscMiss, pscPut, pscRem);
669-
removeShutdownHook();
659+
heartbeatLock.lock();
660+
try {
661+
stopHeartBeatIfRunning();
662+
PoolStatus status = queue.shutdown(fullShutdown);
663+
dataSourceUp.set(false);
664+
if (fullShutdown) {
665+
shutdownExecutor();
666+
}
667+
if (fromHook) {
668+
Log.info("DataSource [{0}] shutdown on JVM exit {1} psc[hit:{2} miss:{3} put:{4} rem:{5}]", name, status, pscHit, pscMiss, pscPut, pscRem);
669+
} else {
670+
Log.info("DataSource [{0}] shutdown {1} psc[hit:{2} miss:{3} put:{4} rem:{5}]", name, status, pscHit, pscMiss, pscPut, pscRem);
671+
removeShutdownHook();
672+
}
673+
} finally {
674+
heartbeatLock.unlock();
670675
}
671676
}
672677

0 commit comments

Comments
 (0)