From cc5ece510360d01ac358cc54353799a5f3a31521 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 14 Jun 2019 21:36:50 +0100 Subject: [PATCH] do not throw exception on shutdown --- .../com/muwire/core/connection/ConnectionAcceptor.groovy | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index 6ee13984..be3a3f82 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -38,6 +38,8 @@ class ConnectionAcceptor { final ExecutorService acceptorThread final ExecutorService handshakerThreads + + private volatile shutdown ConnectionAcceptor(EventBus eventBus, UltrapeerConnectionManager manager, MuWireSettings settings, I2PAcceptor acceptor, HostCache hostCache, @@ -73,11 +75,13 @@ class ConnectionAcceptor { } void stop() { + shutdown = true acceptorThread.shutdownNow() handshakerThreads.shutdownNow() } private void acceptLoop() { + try { while(true) { def incoming = acceptor.accept() log.info("accepted connection from ${incoming.destination.toBase32()}") @@ -93,6 +97,11 @@ class ConnectionAcceptor { } handshakerThreads.execute({processIncoming(incoming)} as Runnable) } + } catch (Exception e) { + log.log(Level.WARNING, "exception in accept loop",e) + if (!shutdown) + throw e + } } private void processIncoming(Endpoint e) {