Skip to content

fix(inbound): send 503 on DispatchNoRuleDrop instead of silently dropping - #696

Closed
simllll wants to merge 1 commit into
livekit:mainfrom
simllll:fix/dispatch-no-rule-drop-sends-503
Closed

simllll wants to merge 1 commit into
livekit:mainfrom
simllll:fix/dispatch-no-rule-drop-sends-503

Conversation

@simllll

@simllll simllll commented May 22, 2026 •

Copy link
Copy Markdown

Problem

When the dispatch layer returns DispatchNoRuleDrop (no matching dispatch rule, or a server-side DROP decision), handleInvite calls cc.Drop() which terminates the SIP transaction without sending any SIP response. However, by the time the dispatch result is evaluated, livekit-sip has already sent 100 Trying and 180 Ringing to the carrier, so the call's existence is already revealed.

The result: the caller hears indefinite ringing. The carrier never receives a final response, keeps the INVITE transaction alive, and only terminates when the caller manually hangs up and a CANCEL arrives. This wastes carrier resources and produces confusing UX.

Observed via SIP trace (Homer/HEP):

+0.000s  INVITE (carrier → kamailio → livekit-sip)
+0.005s  100 Trying
+0.015s  180 Ringing
+0.077s  [livekit-sip closes with 486/flood — no SIP response sent]
+13.1s   CANCEL (caller gave up and hung up)

livekit-sip logs showed Closing inbound call / status=486 / reason=flood with no subsequent Inbound call closed entry, confirming the SIP response was never transmitted. The close() call after Drop() calls CloseWithStatus(), which checks inviteTx != nil to send the response — but Drop() already set inviteTx = nil, so no response is sent.

Fix

Replace cc.Drop() with cc.RespondAndDrop(sip.StatusServiceUnavailable, "Service Unavailable") — the same pattern used by DispatchNoRuleReject and DispatchServiceUnavailable.

RespondAndDrop sends the final response first, then terminates the transaction, so close() / CloseWithStatus() correctly becomes a no-op.

Why 503 and not silent drop?

The intent of DispatchNoRuleDrop appears to be "don't reveal endpoint information." However, since 100 Trying and 180 Ringing are already sent before dispatch runs, the endpoint's existence is already revealed by the time Drop() is called. Sending a 503 at this point leaks no additional information, but it immediately terminates the call at the carrier side instead of leaving it hanging.

The auth-level AuthDrop (which fires before any provisional response is sent) is a different case and correctly remains a silent drop.

Testing

Self-hosted (OSS livekit-server), easiest repro: create an inbound trunk for a number, but no dispatch rule that matches it, then call the number.

  • Before: 100 Trying, 180 Ringing, then nothing - caller hears ringing until they hang up (CANCEL)
  • After: 100, 180, then 503 Service Unavailable right away

Same thing happens for an INVITE that matches no trunk at all (auth returns empty -> accept, then dispatch returns DROP).

TestInboundCallStatusCode/DispatchDrop is updated to expect the 503 and the recorded CallStatusCode, same as DispatchReject.

@simllll
simllll requested a review from a team as a code owner May 22, 2026 19:02
@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #696      +/-   ##
==========================================
+ Coverage   65.25%   69.18%   +3.93%     
==========================================
  Files          51       43       -8     
  Lines        6588     8704    +2116     
==========================================
+ Hits         4299     6022    +1723     
- Misses       1915     2162     +247     
- Partials      374      520     +146     

☔ 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.

@simllll
simllll force-pushed the fix/dispatch-no-rule-drop-sends-503 branch from db21d39 to bf6b08f Compare May 26, 2026 07:39
@simllll

simllll commented May 26, 2026

Copy link
Copy Markdown
Author

cleaned up, now only the relevant change

…ntly dropping

When the dispatch layer returns DispatchNoRuleDrop (e.g. no matching
dispatch rule, or server-side flood decision), the current code calls
cc.Drop() which terminates the SIP transaction without sending any
response. However, by the time the dispatch result is evaluated,
livekit-sip has already sent 100 Trying and 180 Ringing to the carrier,
so the call's existence is already revealed to the caller.

The consequence of the silent drop is that the caller hears indefinite
ringing: the carrier never receives a final response, keeps the INVITE
alive, and only terminates when the caller manually hangs up and a
CANCEL arrives. This wastes carrier resources and delivers a confusing
user experience ("phone rings forever with no answer").

Since the provisional responses already confirm the endpoint to the
caller, sending a 503 Service Unavailable at this point does not leak
any additional information, but it immediately terminates the call on
the carrier side.

Fix: replace cc.Drop() with cc.RespondAndDrop(503) — the same pattern
used by DispatchNoRuleReject and DispatchServiceUnavailable.

Observed via SIP trace (Homer/HEP): INVITE → 100 → 180 → [13 second
gap, no final response] → CANCEL from carrier. livekit-sip logs showed
"Closing inbound call / status=486 / reason=flood" with no corresponding
"Inbound call closed" entry, confirming the SIP response was never sent.
@simllll
simllll force-pushed the fix/dispatch-no-rule-drop-sends-503 branch from bf6b08f to 6bbc00b Compare September 30, 2026 09:59
@simllll

simllll commented Sep 30, 2026 •

Copy link
Copy Markdown
Author

Rebased onto current main (b77a5f4). DispatchNoRuleDrop still calls a bare c.cc.Drop() there, so the ring-until-CANCEL behaviour described above is unchanged.

Test update. #853 (TELCU-30) added TestInboundCallStatusCode/DispatchDrop, which asserts the current silence: no final response after 100/180, and no CallStatusCode. This PR now updates it to expect a final 503 and a recorded CallStatusCode equal to the status sent. Those are the same assertions DispatchReject makes, and the same principle #853 applies elsewhere: record what actually went on the wire. The test's own comment already says the caller "sees the provisional responses and then silence", which is the problem this PR fixes.

On the port-scan rationale. The silent drop came in with #60 ("Support dropping connections to prevent port scans"). That makes sense when nothing has been sent yet. Since the call-flow rework in #165, however, 100 Trying and 180 Ringing go out before dispatch is evaluated. By the time DispatchNoRuleDrop is handled, a scanner already knows the endpoint is live, and the missing final response only affects legitimate callers, whose carrier keeps the INVITE open until they hang up. The auth-level drop, which fires before any provisional response, is untouched and stays silent.

go build ./... and go test ./pkg/... pass. One note: TestTransfer is flaky on main itself (3 of 5 runs failed locally on b77a5f4 without this change), so a red run there is unrelated.

We've been running this in production since May (on v1.3.0; the rebased version on v1.17.0 is rolling out now) and would be glad to drop our fork.

@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: 2 flags

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

Devin Review

@hechen-eng

Copy link
Copy Markdown
Contributor

@simllll thanks for submitting the PR. I am not able to reproduce the issue though.

Reproduce by removing all dispatch rules for a DID, calling it, and observing the caller experience before/after this fix:

Are you using livekit cloud? TheDispatchNoRuleDrop is returned when there is no inbound trunk found. By removing all dispatch rules, you should get DispatchNoRuleReject instead (there was a change around April/May that changed this behavior from drop to reject).

Let me know if you still see the problem.

@simllll

simllll commented Oct 1, 2026

Copy link
Copy Markdown
Author

Hi, thanks for looking into it!

We are self hosting (OSS livekit-server, currently 1.13.7), not cloud - I guess that's the difference.

On OSS it's still a drop in both cases as far as I can see:

  • trunk matched but no dispatch rule: MatchDispatchRuleIter returns ErrNoDispatchMatched and EvaluateSIPDispatchRules turns every ErrNoDispatchMatched into SIPDispatchResult_DROP (livekit/livekit pkg/service/ioservice_sip.go L113-117 in v1.13.7, same on master)
  • no trunk at all: auth comes back empty -> AuthAccept, then we send 100 + 180, dispatch says DROP and nothing else goes out

So the carrier keeps ringing until the caller hangs up. Maybe the drop -> reject change is only in the cloud dispatch service? If it's in OSS somewhere I'd be happy if you could point me to it ;-)

My repro steps in the description were a bit misleading, sorry - updated them. Easiest way on OSS: inbound trunk for the number, but no dispatch rule that matches it. You get 100, 180 and then silence until CANCEL. With this PR you get a 503 right after the 180.

@hechen-eng

Copy link
Copy Markdown
Contributor

I'd prefer the change in livekit/livekit#4927 so that we can preserve the contract that "drop" means drop silently.

cc @dennwc

@nishadmusthafa

Copy link
Copy Markdown
Contributor

Closing as we took care of it here -> livekit/livekit@edb19c9

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.

3 participants