From 41ea4872becfefb4a5975b64adaca9e15040b1e8 Mon Sep 17 00:00:00 2001 From: Robinson Date: Mon, 4 Apr 2022 23:04:27 +0200 Subject: [PATCH] Fixed IPC connection issue --- src/dorkbox/network/Client.kt | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index 971252db..a060068a 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -147,7 +147,7 @@ open class Client( when { // this is default IPC settings remoteAddress.isEmpty() && config.enableIpc -> { - connectIpc(connectionTimeoutSec) + connectIpc(connectionTimeoutSec = connectionTimeoutSec) } IPv4.isPreferred -> { @@ -323,9 +323,14 @@ open class Client( while (timoutInNanos == 0L || System.nanoTime() - startTime < timoutInNanos) { try { val handshakeConnection = if (autoChangeToIpc) { - buildIpcHandshake(ipcSubscriptionId, ipcPublicationId, handshakeTimeout, reliable) + buildIpcHandshake( + ipcSubscriptionId = ipcSubscriptionId, + ipcPublicationId = ipcPublicationId, + connectionTimeoutSec = handshakeTimeout, + reliable = reliable + ) } else { - buildUdpHandshake(handshakeTimeout, reliable) + buildUdpHandshake(connectionTimeoutSec = handshakeTimeout, reliable = reliable) } logger.info(handshakeConnection.clientInfo()) @@ -356,8 +361,14 @@ open class Client( } private suspend fun buildIpcHandshake(ipcSubscriptionId: Int, ipcPublicationId: Int, connectionTimeoutSec: Int, reliable: Boolean): MediaDriverConnection { - logger.info { - "IPC for loopback enabled and aeron is already running. Auto-changing network connection from ${IP.toString(remoteAddress!!)} -> IPC" + if (remoteAddress == null) { + logger.info { + "IPC enabled." + } + } else { + logger.info { + "IPC for loopback enabled and aeron is already running. Auto-changing network connection from ${IP.toString(remoteAddress!!)} -> IPC" + } } // MAYBE the server doesn't have IPC enabled? If no, we need to connect via network instead @@ -373,10 +384,19 @@ open class Client( } catch (e: Exception) { if (remoteAddress == null) { // if we specified that we MUST use IPC, then we have to throw the exception, because there is no IPC - throw ClientException("Unable to connect via IPC to server. No address was specified", e) + val clientException = ClientException("Unable to connect via IPC to server. No address was specified", e) + ListenerManager.cleanStackTraceInternal(clientException) + throw clientException } } + if (remoteAddress == null) { + // if we specified that we MUST use IPC, then we have to throw the exception, because there is no IPC + val clientException = ClientException("Unable to connect via IPC to server. No address was specified") + ListenerManager.cleanStackTraceInternal(clientException) + throw clientException + } + logger.info { "IPC for loopback enabled, but unable to connect. Retrying with address ${IP.toString(remoteAddress!!)}" } // try a UDP connection instead @@ -485,6 +505,7 @@ open class Client( } else { ClientRejectedException("Connection to ${IP.toString(remoteAddress!!)} has incorrect class registration details!!") } + ListenerManager.cleanStackTraceInternal(exception) throw exception }