Skip to content

Fix shared UDP socket retention during continual ICE gathering - #331

Open
CapricornFBQ wants to merge 2 commits into
livekit:m150_releasefrom
CapricornFBQ:review/livekit-1512-shared-socket
Open

CapricornFBQ wants to merge 2 commits into
livekit:m150_releasefrom
CapricornFBQ:review/livekit-1512-shared-socket

Conversation

@CapricornFBQ

Copy link
Copy Markdown

During continual ICE gathering, repeated allocation on failed networks can retain shared UDP sockets after their ports have been destroyed. AllocationSequence owns these sockets and can outlive the ports, allowing unused sockets to accumulate.

This change schedules a shared-socket release check when allocation completes, allocation stops, or a registered port is destroyed. The check releases the socket only when the sequence is stopped or completed and no UDP or TURN port registrations remain.

The check runs asynchronously on the network thread so port destructors can finish using the socket. It rechecks the state when executed, and SafeTask prevents execution if the sequence has already been destroyed. The change preserves continual gathering and retains sockets needed by active ports or later allocation phases.

Related to livekit/rust-sdks#1512.

Validation

  • The official rtc_p2p_unittests target builds successfully on macOS ARM64 with dcheck_always_on=true.
  • The GN header dependency check passes.
  • All 25 scoped tests pass: 12 new regression cases and 13 existing related tests, with no failures or skips.
  • The regression cases cover allocation completion, stopping, port destruction with remaining borrowers, last-borrower destruction, session teardown before a queued check, and repeated failed-network regathering.
  • Validation covers the allocator and port implementations using virtual sockets. LiveKit SDK integration and real-network end-to-end validation remain pending.

Cover allocation completion, stopping, and port destruction with twelve
instances, including session teardown and repeated failed-network regathering.
Observe real socket bindings and UDP/TURN payloads. Check retention after UDP
removal before removing one of two TURN borrowers. Six instances expose
retained bindings before the production fix.

Issue: livekit/rust-sdks#1512
Bug: None
Schedule a guarded network-thread check when allocation stops or completes
and when a registered port retires. Release the shared socket only after the
sequence is terminal and all UDP/TURN registrations are gone.

Deferring the check lets port destructors finish using the socket. Existing
task safety cancels the check if the sequence is destroyed first, while
execution-time state checks preserve future relay allocation and active
borrowers.

Validation: 25 focused tests pass, including 12 new regression instances and
13 existing controls. The 12 new instances pass with the ownership chain
instrumented by ASan in shuffled order. With the old allocator, six instances
fail only because retired socket bindings remain. The official GN rtc_p2p_unittests target builds on macOS ARM64 with DCHECKs
enabled, and all 25 scoped tests pass after test-helper callback cleanup.
The earlier ASan and old-allocator results predate that cleanup. SDK
end-to-end validation remains pending.

Issue: livekit/rust-sdks#1512
Bug: None
@CapricornFBQ

Copy link
Copy Markdown
Author

@cloudwebrtc, could you review this PR when you have a chance, or suggest an appropriate reviewer? It addresses shared UDP socket retention during continual ICE gathering, and the PR description includes the build and test results. Thank you!

@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CapricornFBQ

Copy link
Copy Markdown
Author

I tried signing the CLA again, but the CLA Assistant page still shows a GitHub API rate limit error for the bot account, and the license/cla check remains pending. Could anyone help me?

@CapricornFBQ

Copy link
Copy Markdown
Author

I tried signing the CLA again, but the CLA Assistant page still shows a GitHub API rate limit error for the bot account, and the license/cla check remains pending. Could anyone help me?

Update: I was able to sign the CLA, and the check has passed.”

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.

2 participants