Skip to content

Commit

Permalink
fixup! fixup! KTOR-2036 Fix CIO connection limit
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Sep 1, 2022
1 parent 41b863d commit 0252f21
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -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
}
Expand Down

0 comments on commit 0252f21

Please sign in to comment.