PersistentCache: failure during construction may lead to resource leak
@@ -194,6 +194,8 @@ public class PersistentCache implements Broadcaster.Listener {
}
generations.remove(oldest);
}
+
+ try {
readGeneration = generations.size() > 1 ? generations.first() : -1;
writeGeneration = generations.size() > 0 ? generations.last() : 0;
if (readGeneration >= 0) {
@@ -206,6 +208,11 @@ public class PersistentCache implements Broadcaster.Listener {
writeDispatcherThread = new Thread(writeDispatcher, "Oak CacheWriteQueue");
writeDispatcherThread.setDaemon(true);
writeDispatcherThread.start();
+ } catch (RuntimeException ex) {
+ // OAK-8052: cleanup stores in case of failure
+ LOG.error("Exception during PersistentCache instantiation for {}.", url);
+ close();
+ }
}
private void logUnsupportedWarning(String configKey) {
