Skip to content

Remove TurnServer workarounds, add error-path tests#1530

Open
CraziestPower wants to merge 2 commits intosipsorcery-org:masterfrom
CraziestPower:fix/turn-server-remove-workarounds
Open

Remove TurnServer workarounds, add error-path tests#1530
CraziestPower wants to merge 2 commits intosipsorcery-org:masterfrom
CraziestPower:fix/turn-server-remove-workarounds

Conversation

@CraziestPower
Copy link
Copy Markdown
Contributor

Summary

  • Replace BuildErrorCodeAttribute() workaround with new STUNErrorCodeAttribute(code, reason) at all 8 call sites (fix landed in Fix STUNErrorCodeAttribute(int, string) constructor #1509)
  • Replace VerifyMessageIntegrity() workaround with request.CheckIntegrity(key) (fix landed in Fix CheckIntegrity() failing when FINGERPRINT is absent #1510)
  • Remove the now-unnecessary rawBytes parameter from ProcessMessage/HandleAllocate
  • Add 5 unit tests covering previously untested error-code paths (437 duplicate allocation, 437 refresh/createpermission/channelbind without allocation, 400 malformed channelbind)
  • Extract AssertErrorCode test helper

Test plan

  • dotnet build src/SIPSorcery.sln compiles cleanly
  • dotnet test test/unit/SIPSorcery.UnitTests.csproj -f net8.0 --filter TurnServer — all 17 tests pass (12 existing + 5 new)

Closes #1529

🤖 Generated with Claude Code

Replace BuildErrorCodeAttribute() and VerifyMessageIntegrity() workarounds
with the now-fixed library methods: STUNErrorCodeAttribute(code, reason) and
request.CheckIntegrity(key). Add 5 tests covering the previously untested
error-code paths (437 duplicate allocation, 437 refresh/createpermission/
channelbind without allocation, 400 malformed channelbind) plus an
AssertErrorCode helper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CraziestPower CraziestPower force-pushed the fix/turn-server-remove-workarounds branch from 6a0884a to 0360df1 Compare February 21, 2026 15:11
…rAgent

The CloseWhileReceivingDoesNotThrowUnobservedException test was
intermittently failing on macOS CI because it caught an unobserved
NullReferenceException originating from SIPUserAgent.AcceptAttendedTransfer,
not from UdpReceiver code. This happened because AcceptAttendedTransfer
accesses MediaSession and m_sipDialogue after an await, but by that time
the agent may have been disposed (setting both to null).

Two fixes applied:
- Root cause: add null guards in AcceptAttendedTransfer after the hold
  delay, capturing local references before the null check to avoid TOCTOU
  races. If the call was terminated during hold processing, the transfer
  is cleanly aborted.
- Defense in depth: filter the UnobservedTaskException handler in the
  UdpReceiver test to only capture exceptions whose stack trace mentions
  UdpReceiver, ignoring unrelated leaked exceptions from other tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sipsorcery
Copy link
Copy Markdown
Member

Thanks for the PR. The title does say it relates to TURN but there are changes to the SIPUserAgent that I suspect should be in a different PR.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TurnServer: remove workarounds and add tests for uncovered error paths

2 participants