Skip to content

Read responses already passed up when a client transaction ends - #995

Open
jjaroztegi wants to merge 1 commit into
livekit:mainfrom
jjaroztegi:fix/tx-done-drains-final-response
Open

jjaroztegi wants to merge 1 commit into
livekit:mainfrom
jjaroztegi:fix/tx-done-drains-final-response

Conversation

@jjaroztegi

Copy link
Copy Markdown

An outbound INVITE over TCP/TLS can lose its non-2xx final response and fail with transaction failed to complete (1 intermediate responses). When the lost response is a 407, the authenticated INVITE is never sent (#950). A REFER over UDP is reported failed with transaction failed to complete (0 intermediate responses) in about 1 of 30-40 transfers, although the peer answered 202 and completed the transfer (#906).

Cause: when Timer D is zero (always over TCP/TLS, and over UDP when the response arrives before ClientTx.Init), sipgo deletes the transaction right after passing up the final response. Done and Responses are then both ready, and the select in sipResponse picks Done about half the time.

Change: when Done fires, sipResponse returns a final response already waiting in Responses before reporting a timeout. INVITE, BYE and REFER all wait there. This fixes #950, and the #906 symptom over any transport, independently of livekit/sipgo#18.

Tested: new TestSIPResponseAfterTransactionDone buffers a 100 and a 407 with both channels closed, as sipgo leaves them, and fails without the change. golangci-lint run and go test -race ./pkg/... pass.

Fixes #950

sipgo deletes a client transaction right after passing up its final
response when Timer D is zero: always over TCP/TLS, and over UDP when
the response arrives before Init sets the timer. Done is then closed
with the response still buffered in Responses, and sipResponse's
select picks Done about half of the time. The response is lost and
the request is reported as "transaction failed to complete": a 407
challenge or a rejection to an outbound INVITE, or the 202 to a REFER.

When Done fires, read the responses the transaction already passed up
and return the final one, if any, before reporting a timeout. INVITE,
BYE and REFER all wait in sipResponse.
@jjaroztegi
jjaroztegi requested a review from a team as a code owner November 18, 2026 21:48

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.65%. Comparing base (0460b40) to head (6929941).
⚠️ Report is 470 commits behind head on main.

Files with missing lines Patch % Lines
pkg/sip/outbound.go 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #995      +/-   ##
==========================================
+ Coverage   65.25%   71.65%   +6.39%     
==========================================
  Files          51       47       -4     
  Lines        6588     9263    +2675     
==========================================
+ Hits         4299     6637    +2338     
- Misses       1915     2118     +203     
- Partials      374      508     +134     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant