limited-spring-14213
02/20/2026, 8:47 PMtall-airline-16756
02/20/2026, 8:48 PMtall-airline-16756
02/20/2026, 8:48 PMshutdown() or session.aclose() is called.
What you can do instead
• Control when shutdown is called in your own logic. Make shutdown conditional so it only runs when you actually want the job to end.
• Use shutdown hooks (ctx.add_shutdown_callback()) for cleanup or finalization tasks. Note these hooks run after shutdown has been initiated and cannot stop the shutdown.
• Use graceful shutdown (e.g., session.shutdown(drain=True)) to let pending operations complete before exit. This waits for work to finish but does not allow cancelling the shutdown once started.
Example pattern (preventing shutdown by avoiding calling it)
@session.on("user_state_changed")
async def _user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "away":
if should_continue_session():
return # do not call shutdown()
else:
session.shutdown(drain=True)
If you want, tell me:
• What triggers the shutdown in your setup (explicit code call, external signal, scheduler)?
• Whether you need to delay shutdown to finish work or to conditionally keep a job alive.
With that I can suggest concrete patterns or code changes to ensure shutdown only happens when you intend.
Sources: Job lifecycle | LiveKit Documentationlimited-spring-14213
02/20/2026, 8:49 PMtall-airline-16756
02/20/2026, 8:50 PMempty_timeout=300 to keep it alive 5 minutes after the last participant disconnects).
Example (conceptual)
• Do:
◦ Let participants leave normally; do not call DeleteRoom on participant disconnect.
◦ Create room with empty_timeout if you want a grace period after last leave.
• Don’t:
◦ Trigger room deletion when an individual participant disconnects.
If you want, tell me:
• What currently triggers room shutdown in your system (automatic empty timeout or an explicit API call)?
• Whether you need a specific empty timeout length or logic to keep the room alive under certain conditions.
With that info I can suggest exact code/config changes or show how to set empty_timeout in the SDK you’re using.
Sources: CreateRoom() is taking too long | LiveKit | Why is there extra audio at the end of my recordings of an agent session? |... | Server-side | livekit/livekit_composite | DeepWiki | Python SDKs | livekit/livekit_composite | DeepWiki