Leon Kiefer
06/09/2023, 9:37 AMException 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.e5l
06/09/2023, 9:38 AMLeon Kiefer
06/09/2023, 9:39 AMe5l
06/09/2023, 9:39 AMLeon Kiefer
06/09/2023, 9:46 AMspierce7
06/10/2023, 4:53 AM