Skip to content

Commit 9f7b9bb

Browse files
committed
rtc: skip inherited atexit ffi_dispose in fork children
A fork child inherits the atexit handler but not the native runtime threads; calling livekit_ffi_dispose() on the dead inherited runtime can hang or abort at exit. Guard it with the owning pid so only the process that initialized the FFI disposes it.
1 parent c9b34f6 commit 9f7b9bb

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

livekit-rtc/livekit/rtc/_ffi_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,15 @@ def __init__(self) -> None:
265265
)
266266

267267
ffi_lib = self._ffi_lib
268+
init_pid = self._pid
268269

269270
@atexit.register
270271
def _dispose_lk_ffi() -> None:
272+
# A fork child inherits this handler but not the native runtime
273+
# threads; disposing the inherited (dead) FFI would hang or abort at
274+
# exit. Only the process that initialized it should dispose.
275+
if os.getpid() != init_pid:
276+
return
271277
ffi_lib.livekit_ffi_dispose()
272278

273279
@property

0 commit comments

Comments
 (0)