neworldlt
10/08/2025, 9:40 PMrpc(RpcEndpoints.ADMIN) {
val rawJwt = call.request.queryParameters[Constants.TOKEN_URL]
val session = checkAuth(rawJwt)
//setup services
}
However, if an exception happens, the client never gets an answer:
val rpcClient = client.rpc { ... }
println("#1")
val protectedService = rpcClient.withService<AdminStatusService>()
println("#2")
protectedService.currentUser() // suspend function
println("#3")
Output is:
#1
#2
<Exception from server>
<Timeout>
Is it a bug, or am I doing it totally wrong?neworldlt
10/09/2025, 8:40 PMneworldlt
10/09/2025, 8:49 PMrpcClient.awaitCompletion() too soon returns immediately. I am wondering what the proper way to wait until the client closes is.neworldlt
10/09/2025, 8:50 PMcreateNewClient() somehow triggers initialization.
So I ended with:
val job = launch {
val protectedService = rpcClient.withService<AdminStatusService>()
}
rpcClient.webSocketSession.await()
rpcClient.awaitCompletion()
job.cancel(CancellationException("Socket closed"))Alexander Sysoev
10/13/2025, 11:30 AMHowever, I found that callingThat's a good, point, probably it shouldn'ttoo soon returns immediately. I am wondering what the proper way to wait until the client closes is.rpcClient.awaitCompletion()
Alexander Sysoev
10/13/2025, 11:31 AMIs it a bug, or am I doing it totally wrong?Probably a bug and probably this one https://github.com/Kotlin/kotlinx-rpc/pull/505
neworldlt
10/13/2025, 6:10 PMcallServerStreaming which makes isTransportReady = true. Until it is true awaitCompletion() completes immediateneworldlt
10/13/2025, 6:12 PMisTransportReady check has some good reasons: https://github.com/Kotlin/kotlinx-rpc/commit/df7b1ce46ec07efda6284a916bf41102330dac61
public suspend fun awaitCompletion() {
internalScope.coroutineContext.job.join()
}Alexander Sysoev
10/13/2025, 6:46 PMneworldlt
10/13/2025, 6:53 PMAlexander Sysoev
10/13/2025, 7:20 PM