Fixed issues with connection listenermanagers assignment from a client connection. Added more notes

This commit is contained in:
nathan 2020-08-27 02:33:09 +02:00
parent 7c32c066b4
commit 01d818fa6e
4 changed files with 18 additions and 7 deletions

View File

@ -275,6 +275,8 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
ClientRejectedException(errorMessage))
}
@Suppress("UNCHECKED_CAST")
newConnection.listenerManager.lazySet(listenerManager as ListenerManager<Connection>)
connection = newConnection

View File

@ -245,12 +245,12 @@ open class Server<CONNECTION : Connection>(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<CONNECTION : Connection>(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()
})

View File

@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
}
private val endPoint = connectionParameters.endPoint
private val listenerManager = atomic<ListenerManager<Connection>?>(null)
internal val listenerManager = atomic<ListenerManager<Connection>?>(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()

View File

@ -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
}
}