Skip to content

Commit f7b1175

Browse files
committed
Fix completion handler for client
1 parent c973830 commit f7b1175

File tree

1 file changed

+12
-5
lines changed
  • krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client

1 file changed

+12
-5
lines changed

krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,18 @@ public abstract class KrpcClient : RpcClient, KrpcEndpoint {
159159

160160
clientCancelled = true
161161

162-
if (!clientCancelledByServer) {
163-
sendCancellation(CancellationType.ENDPOINT, null, null, closeTransportAfterSending = true)
164-
}
162+
try {
163+
if (!clientCancelledByServer) {
164+
sendCancellation(CancellationType.ENDPOINT, null, null, closeTransportAfterSending = true)
165+
}
165166

166-
requestChannels.values.forEach { it.close(CancellationException("Client cancelled")) }
167-
requestChannels.clear()
167+
requestChannels.values.forEach {
168+
it.close(CancellationException("Client cancelled"))
169+
it.cancel()
170+
}
171+
} finally {
172+
requestChannels.clear()
173+
}
168174
}
169175

170176
CoroutineScope(context)
@@ -327,6 +333,7 @@ public abstract class KrpcClient : RpcClient, KrpcEndpoint {
327333
throw e
328334
} finally {
329335
channel.close()
336+
channel.cancel()
330337
requestChannels.remove(callId)
331338
connector.unsubscribeFromMessages(call.descriptor.fqName, callId)
332339
}

0 commit comments

Comments
 (0)