Skip to content

Refuse new inbound calls while shutting down - #1003

Draft
JakeHedman wants to merge 1 commit into
livekit:mainfrom
JakeHedman:reject-invites-while-shutting-down
Draft

JakeHedman wants to merge 1 commit into
livekit:mainfrom
JakeHedman:reject-invites-while-shutting-down

Conversation

@JakeHedman

@JakeHedman JakeHedman commented Nov 23, 2026 •

Copy link
Copy Markdown

On SIGTERM the service waits for its calls to end, but it keeps accepting new inbound INVITEs while it waits. A busy server may never empty, and the calls still up when the process is killed are dropped. Outbound already refuses new calls in this state (createSIPParticipant checks Health()). Inbound did not.

With this change, a stopping service answers 503 to an INVITE that would start a call, so the sender can retry on another server.

The check runs after the auth lookup, in two places:

  • AuthAccept: the INVITE is refused.
  • AuthPassword: an INVITE that would get a new 407 is refused. An INVITE with valid credentials is accepted. The nonce is bound to the Call-ID and lives 30 s, so valid credentials answer a challenge that was already sent.

Every other auth result is rejected or dropped as before. Re-INVITEs of calls in progress return before the auth lookup and are not affected.

Notes for review:

  • The check is for HealthStopped only. HealthUnderLoad does not refuse calls.
  • hide_inbound_port is respected: only a sender that matched a trunk gets the 503.
  • The refusal does not go through RespondAndDrop, so it is not stored in the rejected-INVITE cache. That cache is read before the re-INVITE check, so a cached 503 would also answer a later re-INVITE or a retry with credentials for the same Call-ID and From tag. The cost is that a sender that retries at the stopping server gets a new auth lookup and call record each time.
  • A refusal is counted as server_error with the reason shutting-down, the same class as calls ended by shutdown. Say if you prefer indeterminate.
  • There is no config flag. I can add one if you want this to be opt-in.

TestInboundShutdown covers, on a stopping service: a new INVITE, a new INVITE on a password trunk, an inbound re-INVITE, an outbound re-INVITE, and an INVITE that was challenged before the shutdown (a repeat without credentials is refused, the retry with credentials is accepted).

This is the change asked for in #962, which was folded into #963. #770 has an INVITE check together with an OPTIONS change. This PR is only the INVITE part, on current main.

@JakeHedman
JakeHedman requested a review from a team as a code owner November 23, 2026 08:31
devin-ai-integration[bot]

This comment was marked as resolved.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.94%. Comparing base (0460b40) to head (df88b2d).
⚠️ Report is 475 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1003      +/-   ##
==========================================
+ Coverage   65.25%   71.94%   +6.69%     
==========================================
  Files          51       48       -3     
  Lines        6588     9400    +2812     
==========================================
+ Hits         4299     6763    +2464     
- Misses       1915     2128     +213     
- Partials      374      509     +135     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread pkg/sip/inbound.go Outdated
// the sender can retry on another server. Re-INVITEs were handled above.
// The retry of a challenged INVITE is not a new call either: its call
// record is open, and the normal path below closes it.
if cm.mon.Health() == stats.HealthStopped && !cm.challengePending(cc.ID()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟨 Unbound challenge bypasses shutdown admission

During shutdown, processInvite lets an unrelated INVITE through when its To-tag matches a pending challenge. newInbound accepts the supplied tag without checking that it belongs to that Call-ID and From-tag. A peer can start a new call on an otherwise authorized trunk while the server drains.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@JakeHedman
JakeHedman marked this pull request as draft November 23, 2026 11:50
On SIGTERM the service waits for its calls to end, but it kept accepting
new inbound INVITEs while it waited. A busy server could stay up until it
was killed, and the calls still up at that point were dropped.

A stopping service now answers 503 to an INVITE that would start a call,
so that the sender can retry on another server. An INVITE that would get
a new digest challenge is refused in the same way. An INVITE with valid
credentials answers a challenge that was already sent, and is accepted.
Re-INVITEs of calls in progress are not affected.

The refusal is not stored in the rejected-INVITE cache. A cached answer
is replayed before re-INVITEs and retries with credentials are recognized.
@JakeHedman
JakeHedman force-pushed the reject-invites-while-shutting-down branch from deb2768 to df88b2d Compare November 23, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant