mirror of https://github.com/zlatinb/muwire
do not flush the output stream on Endpoint.close(). This fixes the long shutdown time
parent
e5b12701f5
commit
fa9c697bfa
|
@ -27,17 +27,6 @@ import net.i2p.data.Destination
|
||||||
@Log
|
@Log
|
||||||
abstract class Connection implements Closeable {
|
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 int SEARCHES = 10
|
||||||
private static final long INTERVAL = 1000
|
private static final long INTERVAL = 1000
|
||||||
|
|
||||||
|
@ -98,14 +87,8 @@ abstract class Connection implements Closeable {
|
||||||
log.info("closing $name")
|
log.info("closing $name")
|
||||||
reader.interrupt()
|
reader.interrupt()
|
||||||
writer.interrupt()
|
writer.interrupt()
|
||||||
|
endpoint.close()
|
||||||
CountDownLatch latch = new CountDownLatch(1)
|
log.info("closed $name")
|
||||||
CLOSER.submit({
|
|
||||||
endpoint.close()
|
|
||||||
latch.countDown()
|
|
||||||
log.info("closed $name")
|
|
||||||
})
|
|
||||||
latch.await(1000, TimeUnit.MILLISECONDS)
|
|
||||||
eventBus.publish(new DisconnectionEvent(destination: endpoint.destination))
|
eventBus.publish(new DisconnectionEvent(destination: endpoint.destination))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,6 @@ class Endpoint implements Closeable {
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
try {inputStream.close()} catch (Exception ignore) {}
|
try {inputStream.close()} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
if (outputStream != null) {
|
|
||||||
try {outputStream.close()} catch (Exception ignore) {}
|
|
||||||
}
|
|
||||||
if (toClose != null) {
|
if (toClose != null) {
|
||||||
try {toClose.reset()} catch (Exception ignore) {}
|
try {toClose.reset()} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue