Skip to content

Shutdown handler not invoked when call is not received or is disconnected #4392

@sagorbrur

Description

@sagorbrur

Bug Description

When a call is not received or is disconnected prematurely, the shutdown process does not appear to execute as expected. In these scenarios, the shutdown handler is never entered, and the process is eventually forcefully terminated.

As a result, the following errors are logged:

2025-12-25T14:15:32.567988716Z stdout F {"message": "process did not exit in time, killing process", "level": "ERROR", "name": "livekit.agents", "pid": 68, "job_id": "AJ_iMXGj8t3AVnY", "room_id": "RM_dUSn3teUhuCS", "timestamp": "2025-12-25T14:15:32.567808+00:00"}

2025-12-25T14:15:32.568078676Z stdout F {"message": "killing process", "level": "INFO", "name": "livekit.agents", "pid": 68, "job_id": "AJ_iMXGj8t3AVnY", "room_id": "RM_dUSn3teUhuCS", "timestamp": "2025-12-25T14:15:32.568001+00:00"}

Observed behavior

  • The shutdown method is not invoked when the call is unanswered or terminated unexpectedly.
  • The process exceeds the allowed shutdown time and is forcibly killed.

Question
What could be the underlying reason the shutdown handler is not being triggered in this scenario? Are there known conditions under which the shutdown callback may be skipped when a call is not successfully established?

Expected Behavior

When a call is not received or is terminated before being fully established, the application should:

  • Gracefully invoke the shutdown handler.
  • Release all resources associated with the call (e.g., connections, workers, or background tasks).
  • Exit the process cleanly within the configured shutdown timeout.
  • Avoid forceful process termination and related error logs.

Reproduction Steps

1. Start the agent/service and initiate an outbound call to a user.
2. Do one of the following:

   * Allow the call to ring without being answered, **or**
   * Disconnect it immediately.
3. Observe the application lifecycle after the call is not received or is terminated.
4. Wait for the configured shutdown timeout to elapse.
5. Review the application logs.

Operating System

ubuntu 22.04

Models Used

Deepgram, OpenAI, ElevenLab

Package Versions

livekit-agents=1.3.10

Session/Room/Call IDs

roomID: RM_dUSn3teUhuCS

Proposed Solution

Additional Context

No response

Screenshots and Recordings

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions