livekit workers are supposed to stop accepting job...
# ask-ai
i
livekit workers are supposed to stop accepting job requests after receiving a SIGTERM right? if im using a custom request_fnc with my worker, does that override livekits behavior of not accepting jobs after getting a SIGTERM?
t
Thanks for reaching out, Ed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for your question! When a LiveKit worker receives a
SIGTERM
signal, it gracefully stops accepting new job requests by entering a "draining" state. This lets the LiveKit server know not to assign any new jobs. Any job requests that come in before the server fully acknowledges this status will be automatically rejected. But don’t worry—any jobs already in progress will be allowed to finish normally, and the worker stays active until all sessions wrap up or the
drain_timeout
is reached. Also, if you’re using a custom
request_fnc
, it won’t change this behavior. The
request_fnc
is used during regular operations to decide whether to accept or reject jobs. Once the
SIGTERM
signal is received, the worker skips over the
request_fnc
and goes straight into the draining state. This helps ensure a smooth and safe shutdown process. If anything is unclear or if you have more questions, please don’t hesitate to ask—I’m here to help! Sources: agents/src/cli.ts | Deploying to custom environments | LiveKit Docs | Worker options | LiveKit Docs
i
so when i see the log "draining worker" that means the SIGTERM was received, and now the worker will not accept any new jobs? if drain timeout is 0, it should wait to fully shutdown the worker once all calls are finished right?
t
Thank you for reaching out! The log message "draining worker" means that the worker is gracefully shutting down, usually after receiving a
SIGTERM
signal. At this stage, it stops taking on new jobs and focuses on finishing any active ones, so nothing gets interrupted unexpectedly. Also, if the
drain_timeout
is set to
0
, the worker will patiently wait for all current jobs to complete before shutting down. This helps ensure no active sessions are cut off, though it might mean the shutdown takes longer if jobs run over time. If you have any questions or need a hand with this, just let me know—I’m here to help! Sources: Worker lifecycle | LiveKit Docs | livekit-agents/livekit/agents/worker.py | README.md | Worker options | LiveKit Docs | Deploying to custom environments | LiveKit Docs
i
im seeing cases where i see "draining worker" log, and then about 30-40 seconds later, while an active call is still running, the worker begins to shut down. im running the worker with drain timeout equal to 0
t
I understand it can be a bit confusing when your worker shuts down during an active call, especially with
drain_timeout=0
set. What’s likely happening is that your worker is running in development mode. In this mode, graceful draining is turned off, so the worker stops right away when it gets a termination signal, even if there are still active jobs. This is actually helpful for quick restarts and debugging while developing. To make sure your worker waits for active calls to finish before shutting down, you’ll want to run it in production mode (not development mode) and set
drain_timeout
to a suitable non-zero value. If you'd like, I’m here to help you check or update your configuration—just let me know! Sources: livekit-agents/livekit/agents/utils/connection_pool.py
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!