Send local ICE candidates off the transport event loop - #5
Merged
Merged
Conversation
Each local candidate went to the SFU as a blocking IceTrickle RPC on the event loop, one round trip each. The SFU's answer queued behind them, so with ten candidates and a 120 ms round trip the publisher applied its answer, and started ICE, 1.3 s late. Candidates now go out from their own goroutine, still in order and still after the offer, and the answer is applied as soon as it arrives. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each local ICE candidate went to the SFU as a blocking
IceTrickleRPC on the transport's event loop, one round trip each. The SFU's answer toSetPublisheris applied on that same loop, so it queued behind every candidate gathered while the offer was in flight: with ~10 candidates and a 120 ms round trip, the publisher applied its answer, and only then started ICE, about 1.3 s late.pc/pc.go: theOnICECandidateevent still goes through the event loop (so candidates still follow the offer), but only appends the candidate to a queue. A dedicated goroutine sends queued candidates one at a time, in gathering order. A failed send is enqueued back on the event loop so it is handled like any other failed event.TestSlowCandidateSendsDoNotHoldBackTheAnswer(pc/trickle_test.go, with anonICECandidatehook inpc/pc_test.go): every candidate send takes 200 ms; the answer must reach a stable signaling state immediately, and all candidates must still go out in gathering order. Onmainit fails with the answer applied ~1 s late ("999ms is not less than 150ms"); with the change it passes.This is independent of WARP and the pion forks and applies to
mainon its own; the WARP PR includes it.Tested:
go build ./...,go vet ./..., gofumpt,go mod tidyandgo test -race -count=1 ./...pass on the branch.Measured on staging (10-run medians, join to first media, measured with the connection timing from #2):
🤖 Generated with Claude Code