diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index 1e7d7045..c942d14f 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -496,11 +496,6 @@ open class Client( connect0(handshake, handshakeConnection, handshakeTimeoutSec) success = true - - // finished with the handshake, so always close the connection publication - // The subscription is RE-USED, so we don't close that! - handshakeConnection.publication.close() - // once we're done with the connection process, stop trying break } catch (e: ClientRetryException) { @@ -754,6 +749,10 @@ open class Client( throw e } + // finished with the handshake, so always close the connection publication + // The subscription is RE-USED, so we don't close that! + handshakeConnection.publication.close() + isConnected = true logger.debug { "[$aeronLogInfo - ${handshake.connectKey}] Connection (${newConnection.id}) to $remoteAddressString done with handshake." } diff --git a/src/dorkbox/network/handshake/ClientHandshake.kt b/src/dorkbox/network/handshake/ClientHandshake.kt index 24ef2c13..778cedbb 100644 --- a/src/dorkbox/network/handshake/ClientHandshake.kt +++ b/src/dorkbox/network/handshake/ClientHandshake.kt @@ -276,6 +276,10 @@ internal class ClientHandshake( } if (!connectionDone) { + // since this failed, close everything + handshakeConnection.subscription.close() + handshakeConnection.publication.close() + val exception = ClientTimedOutException("Waiting for registration response from server") ListenerManager.cleanStackTraceInternal(exception) throw exception