diff --git a/.nanpa/rpc-race.kdl b/.nanpa/rpc-race.kdl new file mode 100644 index 00000000..6a9e3fe5 --- /dev/null +++ b/.nanpa/rpc-race.kdl @@ -0,0 +1 @@ +patch package="livekit-ffi" type="fixed" "Fix RPC invocation race bug" \ No newline at end of file diff --git a/livekit-ffi/src/server/participant.rs b/livekit-ffi/src/server/participant.rs index afa4bade..e6d78987 100644 --- a/livekit-ffi/src/server/participant.rs +++ b/livekit-ffi/src/server/participant.rs @@ -140,6 +140,8 @@ async fn forward_rpc_method_invocation( let (tx, rx) = oneshot::channel(); let invocation_id = server.next_id(); + room.store_rpc_method_invocation_waiter(invocation_id, tx); + let _ = server.send_event(proto::ffi_event::Message::RpcMethodInvocation( proto::RpcMethodInvocationEvent { local_participant_handle: local_participant_handle as u64, @@ -152,8 +154,6 @@ async fn forward_rpc_method_invocation( }, )); - room.store_rpc_method_invocation_waiter(invocation_id, tx); - rx.await.unwrap_or_else(|_| { Err(RpcError { code: RpcErrorCode::ApplicationError as u32,