Description
When running LiveKit agents on Linux with the default JobExecutorType.PROCESS mode, the agent process crashes with SIGABRT (exit code -6) shortly after connecting to a room and receiving audio tracks.
Environment
- Platform: Linux (Docker container, python:3.10-slim)
- livekit version: 1.1.5
- livekit-agents version: 1.5.2
- rtc-version: 1.1.5
Crash Details
The crash occurs in _ffi_client.py FFI callback:
Fatal Python error: Aborted
Thread 0x... (most recent call first):
File "livekit/rtc/_ffi_client.py", line 198 in to_python_level
File "livekit/rtc/_ffi_client.py", line 164 in ffi_event_callback
Thread 0x... (most recent call first):
File "livekit/rtc/_ffi_client.py", line 104 in put
File "livekit/rtc/_ffi_client.py", line 190 in ffi_event_callback
Multiple threads calling ffi_event_callback → loop.call_soon_threadsafe → _write_to_self concurrently, causing SIGABRT.
Root Cause
The ffi_event_callback is a ctypes CFUNCTYPE callback invoked from Rust FFI multiple threads. When running in PROCESS mode with forkserver multiprocessing context:
- Rust FFI calls the callback from multiple threads
- Python's ctypes callback handling is not thread-safe for concurrent calls
loop.call_soon_threadsafe triggers race condition → SIGABRT
Workaround
Setting job_executor_type=JobExecutorType.THREAD reduces crash probability, but doesn't fully resolve the issue.
Suggested Fix
Add thread synchronization (lock) to ffi_event_callback in _ffi_client.py, or use a single-threaded event queue pattern for FFI callbacks.
Reproduction
from livekit.agents import Agent, AgentSession, JobContext, WorkerOptions, cli
async def entrypoint(ctx: JobContext):
session = AgentSession()
await session.start(agent=Agent(), room=ctx.room)
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Run in Docker on Linux with shm_size: '2gb' and init: true. Join a room with 2 participants publishing audio tracks → crash within 2 seconds.
Description
When running LiveKit agents on Linux with the default
JobExecutorType.PROCESSmode, the agent process crashes withSIGABRT (exit code -6)shortly after connecting to a room and receiving audio tracks.Environment
Crash Details
The crash occurs in
_ffi_client.pyFFI callback:Fatal Python error: Aborted
Thread 0x... (most recent call first):
File "livekit/rtc/_ffi_client.py", line 198 in to_python_level
File "livekit/rtc/_ffi_client.py", line 164 in ffi_event_callback
Thread 0x... (most recent call first):
File "livekit/rtc/_ffi_client.py", line 104 in put
File "livekit/rtc/_ffi_client.py", line 190 in ffi_event_callback
Multiple threads calling
ffi_event_callback→loop.call_soon_threadsafe→_write_to_selfconcurrently, causing SIGABRT.Root Cause
The
ffi_event_callbackis a ctypes CFUNCTYPE callback invoked from Rust FFI multiple threads. When running inPROCESSmode withforkservermultiprocessing context:loop.call_soon_threadsafetriggers race condition → SIGABRTWorkaround
Setting
job_executor_type=JobExecutorType.THREADreduces crash probability, but doesn't fully resolve the issue.Suggested Fix
Add thread synchronization (lock) to
ffi_event_callbackin_ffi_client.py, or use a single-threaded event queue pattern for FFI callbacks.Reproduction