From b072c168b0999bab2f7736d542e7b51ced566ece Mon Sep 17 00:00:00 2001 From: Ben Cherry Date: Tue, 4 Feb 2025 13:57:35 -0800 Subject: [PATCH] Fix RPC invocation race condition (#565) * Fix race condition in rpc invocation * nanpa * fix * nanpa * cgo * sm --- .nanpa/rpc-race.kdl | 1 + livekit-ffi/src/server/participant.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .nanpa/rpc-race.kdl diff --git a/.nanpa/rpc-race.kdl b/.nanpa/rpc-race.kdl new file mode 100644 index 000000000..6a9e3fe50 --- /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 afa4bade2..e6d789876 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,