nice-bear-83533
03/09/2026, 5:30 PMtall-airline-16756
03/09/2026, 5:30 PMtall-airline-16756
03/09/2026, 5:30 PMsession.shutdown() (or before any code path that might close the session).
• Listen for error events as well — an error during shutdown could abort the closing sequence before the close event is emitted.
• If you use async shutdown (aclose() or an async function), ensure you await it. Not awaiting async shutdown could let the process exit before events are emitted.
• If you run inside Docker / containers or use process signals (SIGTERM), confirm the signal is reaching the process and you aren’t force-killing the container before the session can finish cleanup. Look for logs like "draining worker" which indicate the Closing phase is running.
Example listener setup (verify your code matches this pattern)
session.on("close", () => {
console.log("Session has been closed");
});
session.on("error", (err) => {
console.error("Session error:", err);
});
If close still doesn't fire, collect these details
• A minimal code snippet showing: session creation, where you attach on("close", ...), and where/when you call session.shutdown() (or session.aclose()).
• Execution environment: local Node, Docker, Kubernetes, LiveKit Cloud, etc.
• Any logs around shutdown (especially any errors or "draining worker" messages) and whether you see session_state_changed to closed.
• Whether you use multiple session instances or re-create sessions in the same scope.
What I can do next
• If you share a minimal reproducible snippet and the environment, I’ll point out the exact cause or show a corrected example.
• If you prefer, I can list additional debugging steps for containerized environments or async shutdown patterns.
Share the code snippet and environment details and I’ll help pinpoint the issue.
Sources: Agent session | LiveKit Documentation | Deployment reliability on LiveKit Cloud | LiveKit