rsocket-kotlin
rsocket-kotlin copied to clipboard
RSocket Client (ktor-websocket CIO) closes a connection after 5 seconds
I use version 0.15.4 and I see a strange behavior when I use rsocket client for jvm. When client and server were connected thеn after 5 seconds client closes a connection. Keep Alive configuration doesn't help to fix the issue
Server Config
fun Application.configureRSockets() {
install(RSocketSupport) {
server = RSocketServer()
}
}
Client Config
suspend fun connect(): RSocket {
val connector = RSocketConnector {
connectionConfig {
setupPayload {
buildPayload {
data(ByteReadPacket.Empty)
metadata(BearerAuthMetadata("token"))
}
}
keepAlive = KeepAlive(2.days, 90.seconds)
}
}
return connector.connect(WebSocketClientTransport(CIO, host = "localhost", port = 8080))
}
I expect that client won't be to close a connection
Hey, can you post stacktrace with which client close a connection?
Also, can you try to use OkHttp engine?
I would think, that it can be related to some ktor configuration, rather than RSocket. You can also try to adapt some setting of CIO engine via engine property in WebSocketClientTransport function.
Client logs nothing. I have only server logs where I see the following logs
00:42:09.067 [DefaultDispatcher-worker-2] DEBUG Application - 101 Switching Protocols: GET - /. Exception class kotlinx.coroutines.JobCancellationException: DispatchedCoroutine is cancelling]
kotlinx.coroutines.JobCancellationException: DispatchedCoroutine is cancelling
Caused by: kotlinx.coroutines.channels.ClosedReceiveChannelException: Channel was closed
at kotlinx.coroutines.channels.Closed.getReceiveException(AbstractChannel.kt:1108)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.resumeReceiveClosed(AbstractChannel.kt:913)
at kotlinx.coroutines.channels.AbstractSendChannel.helpClose(AbstractChannel.kt:342)
at kotlinx.coroutines.channels.AbstractSendChannel.close(AbstractChannel.kt:271)
at kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(Channel.kt:93)
at io.ktor.websocket.DefaultWebSocketSessionImpl$runIncomingProcessor$1.invokeSuspend(DefaultWebSocketSession.kt:204)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:190)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:513)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveHasNext.resumeReceiveClosed(AbstractChannel.kt:958)
at kotlinx.coroutines.channels.AbstractSendChannel.helpClose(AbstractChannel.kt:342)
at kotlinx.coroutines.channels.AbstractSendChannel.close(AbstractChannel.kt:271)
at kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(Channel.kt:93)
at io.ktor.websocket.RawWebSocketJvm$1.invokeSuspend(RawWebSocketJvm.kt:78)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
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:749)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
I added debug logs to see who was first. Client was faster than server on 15ms. On client side I see that coroutines became inactive. Also I used RX-cli (chrome extension) to connect to server and nothing happens.
OkHttp engine helped me. Thanks a lot
Good it helps! CIO issue can be related to https://youtrack.jetbrains.com/issue/KTOR-4419 I will leave issue opened just for me, If after 2.0.3 it will be reproducible, I will create an issue in ktor youtrack
I can confirm, that it's not reproducible at least with latest version of ktor (2.1.2)