diff --git a/src/dorkbox/network/connection/Connection.kt b/src/dorkbox/network/connection/Connection.kt index b343f781..0a71b3a4 100644 --- a/src/dorkbox/network/connection/Connection.kt +++ b/src/dorkbox/network/connection/Connection.kt @@ -339,6 +339,13 @@ open class Connection(connectionParameters: ConnectionParams<*>) { close(true) } + internal fun closeBlocking() { + runBlocking { + close() + } + } + + /** * Closes the connection, and removes all connection specific listeners */ diff --git a/src/dorkbox/network/handshake/ServerHandshake.kt b/src/dorkbox/network/handshake/ServerHandshake.kt index 121f3d51..21222233 100644 --- a/src/dorkbox/network/handshake/ServerHandshake.kt +++ b/src/dorkbox/network/handshake/ServerHandshake.kt @@ -55,9 +55,7 @@ internal class ServerHandshake(private val logger: KLog .expirationListener { clientConnectKey, connection -> // this blocks until it fully runs (which is ok. this is fast) logger.error { "[${clientConnectKey} Connection (${connection.id}) Timed out waiting for registration response from client" } - runBlocking { - connection.close() - } + connection.closeBlocking() } .build() @@ -435,6 +433,7 @@ internal class ServerHandshake(private val logger: KLog // create a new connection. The session ID is encrypted. + var connection: CONNECTION? = null try { // connection timeout of 0 doesn't matter. it is not used by the server // the client address WILL BE either IPv4 or IPv6 @@ -460,7 +459,7 @@ internal class ServerHandshake(private val logger: KLog logger.info { "Creating new connection from $clientConnection" } - val connection = connectionFunc(ConnectionParams(server, clientConnection, validateRemoteAddress)) + connection = connectionFunc(ConnectionParams(server, clientConnection, validateRemoteAddress)) // VALIDATE:: are we allowed to connect to this server (now that we have the initial server information) val permitConnection = listenerManager.notifyFilter(connection) @@ -469,6 +468,7 @@ internal class ServerHandshake(private val logger: KLog connectionsPerIpCounts.decrementSlow(clientAddress) sessionIdAllocator.free(connectionSessionId) streamIdAllocator.free(connectionStreamId) + connection.closeBlocking() logger.error { "Connection $clientAddressString was not permitted!" }