From b04179631cfc7b2b3fff88f74eab8a867984d42c Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 24 Jun 2022 23:33:13 +0100 Subject: [PATCH] prevent exception on shutodwn reported in GitHub issue #157 --- .../com/muwire/core/hostcache/H2HostCache.groovy | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy index 4a3166f6..b4e32c91 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy @@ -29,6 +29,7 @@ class H2HostCache extends HostCache { private final Map profiles = new HashMap<>() private final Timer timer + private boolean closed private Collection toVerify = new LinkedHashSet<>() @@ -302,6 +303,7 @@ class H2HostCache extends HostCache { public synchronized void stop() { try {timer.cancel()} catch (Exception ignore) {} sql?.close() + closed = true } @Override public synchronized void load() { @@ -346,14 +348,20 @@ class H2HostCache extends HostCache { log.fine("loaded ${allHosts.size()} hosts from db") timer.schedule({ - recycleSQL() - purgeHopeless() - verifyHosts() - recordConnectionCount() + houseKeep() } as TimerTask, 60000, 60000) loaded = true } + private synchronized void houseKeep() { + if (closed) + return + recycleSQL() + purgeHopeless() + verifyHosts() + recordConnectionCount() + } + private synchronized void verifyHosts() { log.fine("starting verification") final long now = System.currentTimeMillis()