-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kRPC: Endpoints do not terminate when the transport does #100
Comments
Hi, thank you for the question! |
I simply expected if a service goes away, that the flow I am consuming will end no matter on what coroutine scope I collect it. In a normal shutdown, krpc protocol sends an end message for all clients, but in a case of an unexpected crash, the coroutine scope of the backing - web socket with ktor krpc - ends but the corresponding client flow doesn't, unless collected on the client's coroutine scope. |
Hm, that sounds not right. Would you be able to provide a reproducer for that behaviour, please? |
Clone this: It builds on your samples but with only jvm server and compose desktop. On completion of flow it should print done. If server is around till end it prints done. If I stop the server process while client collecting the flow simply is stuck and not finished. |
The same applies with single shot requests. Once it succeeds, all operations simply stuck if server goes away. Tell me if you want me to add to this repo a button to make a single shot request so you could see what happens if initial communication to server succeeds but then it goes away. |
I can verify, that this is a bug, I'll rename the ticket |
UPD: maybe ktor specific, see https://youtrack.jetbrains.com/issue/KTOR-7234/WebSocketSessions-job-does-not-complete-on-abrupt-closure |
I will verify. |
Mmmm, seems like it depends on api usage. This server:
And this client:
Doesn't reproduce the same issue. |
I guess it's specific to the |
Oh, and also in your repro there is no |
Any update on this? But from last attempts, seems that new requests simply get cancelation if web socket session ended, but existing flow still doesn't end. |
And in general, I think exposing some api to know when backing web socket is connected would be great. |
Hi! We fixed the issue from our side, but the bug persists in Ktor
|
OK, I see. |
Probably just the current implementation approach. It may change later |
And now I saw that you opened the issue for Ktor. Client should be like this (and then it works): val ktorClient = HttpClient {
install(WebSockets)
}
val session = ktorClient.webSocketSession(host = "localhost", port = 8080, path = "/test")
session.coroutineContext.job.invokeOnCompletion {
println("completed")
}
session.incoming.consumeEach {
println((it as Frame.Text).readText())
}
session.coroutineContext.job.join()
ktorClient.close() Server easier to debug with this, but not a must: install(WebSockets)
routing {
webSocket("/test") {
var i = 1
while (true) {
delay(1.seconds)
outgoing.send(Frame.Text("test ${i++}"))
}
}
} But main take away from server is to install WeSockets plugin, not RPC plugin (This is your kotlinx-rpc plugin), |
Hello.
I don't know if it is an issue or not, but I definitely find it weird.
It seems like there is no way of telling when the client is disconnected like a status flow, or on disconnection lambda to register.
Right now when I consume flow and server goes away, the flow is now completed.
As a workaround I created my little helper flows (Also to maintain single client for my app), like so:
I wonder if it is the intended use or am I missing something or should the interface or behavior change?
Thanks,
Shay Oinif
The text was updated successfully, but these errors were encountered: