Keep the in-flight read when an injected packet wins nextPacket - #1
Merged
Merged
Conversation
An injected (DTLS-in-STUN) packet winning the select left the spawned nextConn read running. Whatever it read next went into a channel nobody received from, so each piggybacked handshake packet silently dropped one later packet from the peer (SCTP DATA, SACKs and their retransmissions), stalling data channels for seconds after a SPED handshake. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
cnderrauber
marked this pull request as ready for review
September 27, 2026 14:45
cnderrauber
approved these changes
Sep 27, 2026
cnderrauber
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, thank you!
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.
Problem
With SPED (DTLS-in-STUN),
nextPacketstarts a newnextConnread on every call and races it againstinboundPacketInject. When an injected packet wins, that read keeps running, and the next packet it receives goes into a channel nobody reads, so it's lost. Each piggybacked handshake packet therefore drops one of the peer's later packets.I found this while enabling WARP in the Swift SDK (livekit/client-sdk-swift#1138). It was tested against a local
livekit-server1.13.7 withrtc.enable_warp: true, which uses this fork atv3.1.5-warp.1.Fix
Keep the in-flight read on the
Conn(it's owned by the single read loop) and reuse it on the next call instead of starting another.Measurements
Swift SDK client with SPED+SNAP, local server, loopback. n=10 for first messages, n=5 for bursts.
v3.1.5-warp.1The same tests against a server with WARP disabled give 11–14 ms and 100/100. Connect time (
BM-CONN) is unchanged by this fix.go test ./...passes.Related: livekit/ice#4 fixes a second WARP issue, the ~95 ms connect penalty for clients without SPED.