From 66bb4eef5bf165aa7a3ee62fbeae8015b8ca2ccb Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 1 Oct 2019 07:50:29 +0100 Subject: [PATCH] close outbound establishments on a separate thread --- .../core/connection/ConnectionEstablisher.groovy | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy index fee58294..b2553d92 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy @@ -31,7 +31,7 @@ class ConnectionEstablisher { final HostCache hostCache final Timer timer - final ExecutorService executor + final ExecutorService executor, closer final Set inProgress = new ConcurrentHashSet() @@ -51,6 +51,8 @@ class ConnectionEstablisher { rv.setName("connector-${System.currentTimeMillis()}") rv } as ThreadFactory) + + closer = Executors.newSingleThreadExecutor() } void start() { @@ -60,6 +62,7 @@ class ConnectionEstablisher { void stop() { timer.cancel() executor.shutdownNow() + closer.shutdown() } private void connectIfNeeded() { @@ -120,8 +123,10 @@ class ConnectionEstablisher { } private void fail(Endpoint endpoint) { - endpoint.close() - eventBus.publish(new ConnectionEvent(endpoint: endpoint, incoming: false, leaf: false, status: ConnectionAttemptStatus.FAILED)) + closer.execute { + endpoint.close() + eventBus.publish(new ConnectionEvent(endpoint: endpoint, incoming: false, leaf: false, status: ConnectionAttemptStatus.FAILED)) + } as Runnable } private void readK(Endpoint e) { @@ -175,7 +180,7 @@ class ConnectionEstablisher { log.log(Level.WARNING,"Problem parsing post-rejection payload",ignore) } finally { // the end - e.close() + closer.execute({e.close()} as Runnable) } }