Repository navigation
Kill a handler still running 30 s after a stop request - #557
Conversation
Delete, WHIP delete and update all end a session by asking the handler to stop over IPC and trusting it to exit. A handler that cannot stop, such as one blocked before its pipeline starts, never exits, so the session stays open until the pod is killed. The existing SIGKILL fallback cannot catch this: it runs from IngressEnded, which only happens after the handler has already exited. Arm a 30 second timer on the first termination request and SIGKILL the handler if it is still running when it fires. KillIngress waits for the pipeline to finish, so a healthy handler is long gone by then. The started process is published atomically so the timer reads it without racing the relaunch loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateIngress, DeleteIngress and DeleteWHIPResource ignored their requests and ran the same kill sequence. Move it into killIngress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| func (p *process) killIngress(ctx context.Context) (*livekit.IngressState, error) { | ||
| p.killAfter(killGracePeriod) |
There was a problem hiding this comment.
🔴 Canceled requests kill active ingress sessions
When a stop request expires before IPC delivery, killAfter still kills the healthy handler 30 seconds later. killIngress never disarms the timer when KillIngress returns an error, so an active stream ends unexpectedly.
Learn more
A stop RPC can fail before reaching the handler. The service starts the force-kill timer before calling KillIngress, which uses the caller's context. If that context has already expired, gRPC returns without delivering the stop signal. The timer still fires and kills a handler that has received no request. The current one-shot fuse also prevents a later successful request from starting a new timer.
Example: A client sends DeleteIngress while the handler's IPC server is starting, then its request times out. IPC never delivers KillIngress; the handler starts streaming normally, but the pending timer kills it 30 seconds after the canceled request.
Recommended fix: Arm the force-kill fallback only after the stop signal has actually been delivered, or use a stop protocol that acknowledges receipt independently of waiting for pipeline completion. Keep a timer for acknowledged stop requests even when their response times out.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
All three RPCs that arm the timer are requests to end the session, so ending it when the IPC call fails is intended: before this change, a lost delete left the session running. The service also can't tell an undelivered KillIngress from a delivered one that is waiting on a hung pipeline: both return the context error.
…stop A handler killed by the termination fallback never publishes its final state, so the ingress kept its last reported status after the session ended. Publish ENDPOINT_ERROR from the service once such a handler has exited. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Devin Review found 3 new potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| if h.forceKilled.Load() { | ||
| s.publishKilledState(context.WithoutCancel(ctx), p) | ||
| } |
There was a problem hiding this comment.
🔴 Stalled state update blocks session cleanup
When UpdateIngressState stalls after a forced kill, runHandler cannot end the session. Its uncancelable update runs before SessionEnded and IngressEnded, leaving the session active despite the dead handler.
Learn more
The process manager reaps the killed handler before its deferred cleanup runs. The new state update uses a context without cancellation or deadline and runs synchronously ahead of SessionEnded and IngressEnded. If the state notifier waits indefinitely, neither cleanup call runs; the session stays registered and service shutdown waits for it.
Example: A killed handler exits while the IOInfo state-update RPC remains unresponsive. The updater waits, so IngressEnded never removes the session even though its process is gone.
Recommended fix: Bound the final update with a timeout and ensure cleanup executes even if the notifier stalls. Preserve the final-state-before-session-ended ordering when the update completes.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
serviceStateNotifier sends this over psrpc, which bounds every request with its 3 s default client timeout when the context has no deadline, so the update cannot hold up SessionEnded and IngressEnded.
The ERROR update for a killed handler started from the service's copy of the ingress info, which only holds the state from session start. It cleared the room and tracks the handler had reported, and carried the old UpdatedAt, so it looked older than the updates it was meant to replace. Keep the last state each handler reports and build the final update from it, with UpdatedAt set to the time of the kill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Delete, WHIP delete and update end a session by asking the handler to stop over IPC, then waiting for it to exit. A handler that cannot stop never exits, so its session stays active until the pod is stopped. The WHIP relay hang fixed in #556 is one such case. The existing SIGKILL fallback in
sessionClosercannot catch it: it runs fromIngressEnded, which only fires after the handler process has exited.Change
The first
DeleteIngress,DeleteWHIPResourceorUpdateIngresscall for a handler starts a 30 s timer (killGracePeriod). If the handler process is still running when the timer fires, it gets SIGKILL and a warning is logged. Later requests do not restart the timer.The started process is stored in an
atomic.Pointer, so the timer reads it without racing the relaunch loop.UpdateIngress,DeleteIngressandDeleteWHIPResourcenow share onekillIngresshelper, since all three ignored their request.A handler killed this way never sends its final state, so once it has exited the service publishes
ENDPOINT_ERROR("handler killed after it did not stop") instead. The service keeps the last state each handler reports, and builds this update from it withUpdatedAtset to the time of the kill.Verified
TestKillAfterKillsHandlerStillRunningstartssleep 60, arms the timer with 50 ms, and expects the process to exit with "signal: killed". It tests the new path only, so there is no older behavior for it to fail against.ENDPOINT_ERRORonce the handler exits.TestUpdateIngressStateRecordsTracksAndForwardschecks that the final update keeps the tracks the handler last reported and has a newerUpdatedAt. It fails without the stored state.go build ./...andgo test -race ./pkg/...pass.Not done yet
DELETEand the room never removes the ingress participant.🤖 Generated with Claude Code