enough-dentist-75383
12/10/2025, 1:18 PMtall-airline-16756
12/10/2025, 1:18 PMtall-airline-16756
12/10/2025, 1:19 PMperform_rpc raised RpcError: Failed to send and the engine error engine is closed.
• That means the client-side connection/session was already closing or closed when _clear_buffer_task attempted to send the RPC.
What you can do now
• Cancel or stop background cleanup tasks (like _clear_buffer_task) before shutting down the session.
• Prevent RPCs after disconnect by checking connection state or listening for the room disconnect event and gating RPC calls.
• Wrap perform_rpc in try/except to handle RpcError and avoid noisy errors during shutdown.
Quick code patterns
• Cancel tasks on shutdown or on disconnected event.
• Example RPC error handling:
try:
await participant.perform_rpc(...)
except rpc.RpcError as e:
logger.warning(f"RPC failed: {e}")
If you want, tell me:
• whether this happens every shutdown or only sometimes,
• how you trigger room shutdown (manual/timeout/crash),
• and the agent lifecycle code around _clear_buffer_task.
I can then suggest where to add cancellation checks or show a small patch to avoid the race.
Sources: Remote method calls | LiveKit docs | client-sdk-js | livekit/livekit_composite | DeepWiki | Connecting to LiveKit | LiveKit docs | Agent speech and audio | LiveKit docs | Virtual avatar plugins | LiveKit Docs