do not throw exception on shutdown

pull/5/head
Zlatin Balevsky 2019-06-14 21:36:50 +01:00
parent db7e21e343
commit cc5ece5103
1 changed files with 9 additions and 0 deletions

View File

@ -38,6 +38,8 @@ class ConnectionAcceptor {
final ExecutorService acceptorThread final ExecutorService acceptorThread
final ExecutorService handshakerThreads final ExecutorService handshakerThreads
private volatile shutdown
ConnectionAcceptor(EventBus eventBus, UltrapeerConnectionManager manager, ConnectionAcceptor(EventBus eventBus, UltrapeerConnectionManager manager,
MuWireSettings settings, I2PAcceptor acceptor, HostCache hostCache, MuWireSettings settings, I2PAcceptor acceptor, HostCache hostCache,
@ -73,11 +75,13 @@ class ConnectionAcceptor {
} }
void stop() { void stop() {
shutdown = true
acceptorThread.shutdownNow() acceptorThread.shutdownNow()
handshakerThreads.shutdownNow() handshakerThreads.shutdownNow()
} }
private void acceptLoop() { private void acceptLoop() {
try {
while(true) { while(true) {
def incoming = acceptor.accept() def incoming = acceptor.accept()
log.info("accepted connection from ${incoming.destination.toBase32()}") log.info("accepted connection from ${incoming.destination.toBase32()}")
@ -93,6 +97,11 @@ class ConnectionAcceptor {
} }
handshakerThreads.execute({processIncoming(incoming)} as Runnable) 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) { private void processIncoming(Endpoint e) {