diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index 103fc85a..f781fc7d 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -38,6 +38,7 @@ import dorkbox.network.handshake.ClientConnectionDriver import dorkbox.network.handshake.ClientHandshake import dorkbox.network.handshake.ClientHandshakeDriver import dorkbox.network.ping.Ping +import dorkbox.util.Sys import org.slf4j.LoggerFactory import java.net.Inet4Address import java.net.Inet6Address @@ -540,10 +541,21 @@ open class Client(config: ClientConfiguration = ClientC (config.enableIpc && (remoteAddress == null || isSelfMachine)) || (!config.enableIpc && remoteAddress == null) // how long does the initial handshake take to connect - var handshakeTimeoutNs = TimeUnit.SECONDS.toNanos(config.connectionCloseTimeoutInSeconds.toLong()) + aeronDriver.publicationConnectionTimeoutNs() + aeronDriver.lingerNs() + val aeronTimeoutNs = aeronDriver.publicationConnectionTimeoutNs() + aeronDriver.lingerNs() + var handshakeTimeoutNs = TimeUnit.SECONDS.toNanos(config.connectionCloseTimeoutInSeconds.toLong()) + if (handshakeTimeoutNs < aeronTimeoutNs) { + handshakeTimeoutNs += aeronTimeoutNs + logger.warn("Handshake timeout is less than aeron timeout, increasing timeout to ${Sys.getTimePrettyFull(handshakeTimeoutNs)} to prevent aeron timeout issues") + } + // how long before we COMPLETELY give up retrying. A '0' means try forever. var connectionTimoutInNs = TimeUnit.SECONDS.toNanos(connectionTimeoutSec.toLong()) + if (connectionTimoutInNs in 1..