From 1273c8f386e1c97a7f9007977aecd5a77ee2e93a Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 3 Sep 2020 22:23:17 +0200 Subject: [PATCH] Potential fix for race conditions when closing the endpoint wrt RMI support --- src/dorkbox/network/connection/EndPoint.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dorkbox/network/connection/EndPoint.kt b/src/dorkbox/network/connection/EndPoint.kt index cb969032..c27532d3 100644 --- a/src/dorkbox/network/connection/EndPoint.kt +++ b/src/dorkbox/network/connection/EndPoint.kt @@ -292,7 +292,7 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A val aeronDirectory = config.aeronLogDirectory!!.absolutePath if (!isRunning()) { - logger.debug { "Starting Aeron Media driver..."} + logger.debug("Starting Aeron Media driver...") mediaDriverContext .dirDeleteOnStart(true) @@ -719,17 +719,19 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A aeron?.close() mediaDriver?.close() - // the storage is closed via this as well - settingsStore.close() - - rmiGlobalSupport.close() - runBlocking { connections.forEach { it.close() } } + + // the storage is closed via this as well. + settingsStore.close() + // Connections are closed first, because we want to make sure that no RMI messages can be received + // when we close the RMI support objects (in which case, weird - but harmless - errors show up) + rmiGlobalSupport.close() + close0() // if we are waiting for shutdown, cancel the waiting thread (since we have shutdown now)