diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index a5f99c2e..c8262eb4 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -275,6 +275,8 @@ open class Client(config: Configuration = Configuration ClientRejectedException(errorMessage)) } + @Suppress("UNCHECKED_CAST") + newConnection.listenerManager.lazySet(listenerManager as ListenerManager) connection = newConnection diff --git a/src/dorkbox/network/Server.kt b/src/dorkbox/network/Server.kt index 996cbae1..12a0a6bc 100644 --- a/src/dorkbox/network/Server.kt +++ b/src/dorkbox/network/Server.kt @@ -245,12 +245,12 @@ open class Server(config: ServerConfiguration = ServerC var shouldCleanupConnection = false if (connection.isExpired()) { - logger.debug {"[${connection.sessionId}] connection expired"} + logger.trace {"[${connection.sessionId}] connection expired"} shouldCleanupConnection = true } else if (connection.isClosed()) { - logger.debug {"[${connection.sessionId}] connection closed"} + logger.trace {"[${connection.sessionId}] connection closed"} shouldCleanupConnection = true } @@ -265,11 +265,14 @@ open class Server(config: ServerConfiguration = ServerC false } }, { connectionToClean -> - logger.debug {"[${connectionToClean.sessionId}] removed connection"} - // have to free up resources! handshake.cleanup(connectionToClean) + // there are 2 ways to call close. + // MANUALLY + // when a connection is disconnected via a timeout/expire. + // the compareAndSet is used to make sure that if we call close() MANUALLY, when the auto-cleanup/disconnect is called -- it doesn't + // try to do it again. connectionToClean.close() }) diff --git a/src/dorkbox/network/connection/Connection.kt b/src/dorkbox/network/connection/Connection.kt index 720eaeeb..60799419 100644 --- a/src/dorkbox/network/connection/Connection.kt +++ b/src/dorkbox/network/connection/Connection.kt @@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) { } private val endPoint = connectionParameters.endPoint - private val listenerManager = atomic?>(null) + internal val listenerManager = atomic?>(null) val logger = endPoint.logger @@ -297,8 +297,15 @@ open class Connection(connectionParameters: ConnectionParams<*>) { * Closes the connection, and removes all connection specific listeners */ suspend fun close() { + // there are 2 ways to call close. + // MANUALLY + // when a connection is disconnected via a timeout/expire. + // the compareAndSet is used to make sure that if we call close() MANUALLY, when the auto-cleanup/disconnect is called -- it doesn't + // try to do it again. + + // the server 'handshake' connection info is cleaned up with the disconnect via timeout/expire. if (isClosed.compareAndSet(expect = false, update = true)) { - // the server 'handshake' connection info is already cleaned up before this is called + logger.info {"[${sessionId}] closed connection"} subscription.close() diff --git a/src/dorkbox/network/connection/EndPoint.kt b/src/dorkbox/network/connection/EndPoint.kt index 9bb16360..284f7360 100644 --- a/src/dorkbox/network/connection/EndPoint.kt +++ b/src/dorkbox/network/connection/EndPoint.kt @@ -698,7 +698,6 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A // don't need anything fast or fancy here, because this method will only be called once connections.forEach { it.close() - listenerManager.notifyDisconnect(it) // if disconnect has a "connect" in it, this will case SO MANY PROBLEMS } }