Hi, we are facing some issue with CIO client engin...
# ktor
l
Hi, we are facing some issue with CIO client engine (version 2.3.0) when doing concurrent requests:
Copy code
Exception in thread "main" java.lang.IllegalStateException: The number of released permits cannot be greater than 100
	at kotlinx.coroutines.sync.SemaphoreImpl.release(Semaphore.kt:184)
	at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:32)
	at io.ktor.client.engine.cio.ConnectionFactory$connect$1.invokeSuspend(ConnectionFactory.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Looks like more permits are released then the maximum in this code here https://github.com/ktorio/ktor/blob/2.3.0/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/ConnectionFactory.kt This only happens while doing many PUT requests with huge bodies (batch) and long response times. There are also some
io.ktor.client.network.sockets.ConnectTimeoutException
and
java.io.EOFException
which we are retrying. We have limited the concurrency of requests to 5 by using an additional Semaphore. In a different part of the application we are doing GET requests with a concurrency of 100 and 1000 rps with the same ktor client without any problems.
e
Hey @Leon Kiefer, could you log an issue?
l
in Github or YouTrack?
e
YouTrack would be great
l
s
In the mean time, why not move to Netty instead of CIO to see if that resolves your issue?