From fa9c697bfaa4ce3a0ea72d5a3e222f2196d29199 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 29 Oct 2019 12:38:41 +0000 Subject: [PATCH] do not flush the output stream on Endpoint.close(). This fixes the long shutdown time --- .../muwire/core/connection/Connection.groovy | 21 ++----------------- .../muwire/core/connection/Endpoint.groovy | 3 --- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy index 0dad76b6..8af9b51d 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -27,17 +27,6 @@ import net.i2p.data.Destination @Log abstract class Connection implements Closeable { - /** - * This exists because the reset() method blocks for a long time - * even though the javadocs say it's non-blocking. When that gets - * fixed on the I2P side, this can be removed. - */ - private static final ExecutorService CLOSER = Executors.newCachedThreadPool( {r -> - def rv = new Thread(r,"connection closer") - rv.setDaemon(true) - rv - } as ThreadFactory) - private static final int SEARCHES = 10 private static final long INTERVAL = 1000 @@ -98,14 +87,8 @@ abstract class Connection implements Closeable { log.info("closing $name") reader.interrupt() writer.interrupt() - - CountDownLatch latch = new CountDownLatch(1) - CLOSER.submit({ - endpoint.close() - latch.countDown() - log.info("closed $name") - }) - latch.await(1000, TimeUnit.MILLISECONDS) + endpoint.close() + log.info("closed $name") eventBus.publish(new DisconnectionEvent(destination: endpoint.destination)) } diff --git a/core/src/main/groovy/com/muwire/core/connection/Endpoint.groovy b/core/src/main/groovy/com/muwire/core/connection/Endpoint.groovy index dff4b5e9..a4263236 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Endpoint.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Endpoint.groovy @@ -31,9 +31,6 @@ class Endpoint implements Closeable { if (inputStream != null) { try {inputStream.close()} catch (Exception ignore) {} } - if (outputStream != null) { - try {outputStream.close()} catch (Exception ignore) {} - } if (toClose != null) { try {toClose.reset()} catch (Exception ignore) {} }