From 0252f21b6db56d82d65732a032d4fbff24d9a17b Mon Sep 17 00:00:00 2001 From: "leonid.stashevsky" Date: Thu, 1 Sep 2022 10:55:40 +0200 Subject: [PATCH] fixup! fixup! KTOR-2036 Fix CIO connection limit --- .../src/io/ktor/client/engine/cio/ConnectionFactory.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/ConnectionFactory.kt b/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/ConnectionFactory.kt index 8b114df285..dd2c3139dc 100644 --- a/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/ConnectionFactory.kt +++ b/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/ConnectionFactory.kt @@ -22,12 +22,14 @@ internal class ConnectionFactory( configuration: SocketOptions.TCPClientSocketOptions.() -> Unit = {} ): Socket { limit.acquire() - addressLimit.computeIfAbsent(address) { Semaphore(addressConnectionsLimit) }.acquire() + val addressSemaphore = addressLimit.computeIfAbsent(address) { Semaphore(addressConnectionsLimit) } + addressSemaphore.acquire() return try { aSocket(selector).tcpNoDelay().tcp().connect(address, configuration) } catch (cause: Throwable) { // a failure or cancellation + addressSemaphore.release() limit.release() throw cause }