From db385d0c1a4e7596e6ac74cdd1a4330f2b1bfb80 Mon Sep 17 00:00:00 2001 From: Robinson Date: Wed, 9 Aug 2023 21:23:52 -0600 Subject: [PATCH] inUse check now uses the endpoint for extra checks --- src/dorkbox/network/aeron/AeronDriver.kt | 4 ++-- src/dorkbox/network/aeron/AeronDriverInternal.kt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dorkbox/network/aeron/AeronDriver.kt b/src/dorkbox/network/aeron/AeronDriver.kt index 668a8543..7858852c 100644 --- a/src/dorkbox/network/aeron/AeronDriver.kt +++ b/src/dorkbox/network/aeron/AeronDriver.kt @@ -164,7 +164,7 @@ class AeronDriver private constructor(config: Configuration, val logger: KLogger driverConfigurations.forEach { entry -> val driver = entry.value - val closed = if (traceEnabled) driver.isInUse(logger) else driver.isRunning() + val closed = if (traceEnabled) driver.isInUse(null, logger) else driver.isRunning() if (closed) { logger.error { "Aeron Driver [${driver.driverId}]: still running during check (${driver.aeronDirectory})" } @@ -176,7 +176,7 @@ class AeronDriver private constructor(config: Configuration, val logger: KLogger // this is already checked if we are in trace mode. driverConfigurations.forEach { entry -> val driver = entry.value - if (driver.isInUse(logger)) { + if (driver.isInUse(null, logger)) { logger.error { "Aeron Driver [${driver.driverId}]: still in use during check (${driver.aeronDirectory})" } return@withLock false } diff --git a/src/dorkbox/network/aeron/AeronDriverInternal.kt b/src/dorkbox/network/aeron/AeronDriverInternal.kt index d4ca9d3e..3ba477c2 100644 --- a/src/dorkbox/network/aeron/AeronDriverInternal.kt +++ b/src/dorkbox/network/aeron/AeronDriverInternal.kt @@ -710,14 +710,13 @@ internal class AeronDriverInternal(endPoint: EndPoint<*>?, private val config: C return context.isRunning() } - suspend fun isInUse(logger: KLogger): Boolean { + suspend fun isInUse(endPoint: EndPoint<*>?, logger: KLogger): Boolean { // as many "sort-cuts" as we can for checking if the current Aeron Driver/client is still in use if (!isRunning()) { logger.trace { "Aeron Driver [$driverId]: not running" } return false } - val driverId = config.id if (registeredPublications.value > 0) { if (logger.isTraceEnabled) { val elements = registeredPublicationsTrace.elements @@ -740,7 +739,7 @@ internal class AeronDriverInternal(endPoint: EndPoint<*>?, private val config: C return true } - if (endPointUsages.isNotEmpty()) { + if (endPointUsages.size > 1 && !endPointUsages.contains(endPoint)) { logger.debug { "Aeron Driver [$driverId]: still referenced by ${endPointUsages.size} endpoints" } return true } @@ -799,6 +798,7 @@ internal class AeronDriverInternal(endPoint: EndPoint<*>?, private val config: C if (isInUse(logger)) { logger.debug { "Aeron Driver [$driverId]: in use, not shutting down this instance." } return@withLock false + if (isInUse(endPoint, logger)) { } val removed = AeronDriver.driverConfigurations[driverId]