Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ffi-client-singleton-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-rtc": patch
---

Create the shared `FfiClient` under a lock, so rooms connected from several threads at once no longer lose their connect callback and panic the process.
11 changes: 8 additions & 3 deletions livekit-rtc/livekit/rtc/_ffi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,17 @@ def to_python_level(level: proto_ffi.LogLevel.ValueType) -> Optional[int]:
class FfiClient:
_instance: Optional["FfiClient"] = None
_ffi_disposed: bool = False
_instance_lock = threading.Lock()

@classproperty
def instance(cls) -> "FfiClient":
if cls._instance is None:
cls._instance = FfiClient()
return cls._instance
if cls._instance is not None:
return cls._instance
# threads that race here would each get their own client and lose events sent to the other
with cls._instance_lock:
if cls._instance is None:
cls._instance = FfiClient()
return cls._instance

def __init__(self) -> None:
FfiClient._ffi_disposed = False
Expand Down
Loading