Skip to content

Commit eee260c

Browse files
committed
rtc: quietly skip FfiHandle drop in fork children
FfiHandle.__del__ runs when a child GCs handles inherited across fork(). It routes through FfiClient.instance, which now raises the fork guard, so Python prints 'Exception ignored in __del__' to stderr. Swallow the guard in dispose(): the handle belongs to the parent's FFI and is reclaimed on process exit anyway.
1 parent 9f7b9bb commit eee260c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

livekit-rtc/livekit/rtc/_ffi_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ def disposed(self) -> bool:
8383
def dispose(self) -> None:
8484
if self.handle != INVALID_HANDLE and not self._disposed:
8585
self._disposed = True
86-
assert FfiClient.instance._ffi_lib.livekit_ffi_drop_handle(ctypes.c_uint64(self.handle))
86+
try:
87+
ffi = FfiClient.instance
88+
except RuntimeError:
89+
# Inherited across fork(): the handle belongs to the parent's
90+
# FFI and is reclaimed when this process exits. Skip quietly so
91+
# __del__ in the child doesn't spam "Exception ignored" to stderr.
92+
return
93+
assert ffi._ffi_lib.livekit_ffi_drop_handle(ctypes.c_uint64(self.handle))
8794

8895
def __repr__(self) -> str:
8996
return f"FfiHandle({self.handle})"

0 commit comments

Comments
 (0)