Repository navigation
sfu: bind retransmissions to the source cache generation - #5213
Conversation
|
cc @boks1971 @cnderrauber, since you reviewed our earlier SFU change in #4681. |
|
Critical architectural fix for in-flight NACK packet retransmission during ICE restarts and track resets. When a receiver resets its sequence space, asynchronous NACK repair workers holding previous snapshots can easily cross-contaminate sequence numbers across stream discontinuities. Carrying an opaque *buffer.StreamGeneration token through ExtPacket and validating under the buffer read lock cleanly prevents stale media pairing without introducing lock contention on the hot packet path. One nuance to verify in the DownTrack sequencer: when ReadRTP rejects an obsolete generation read, ensuring the sequencer immediately emits silence padding or records the packet as dropped prevents the downstream WebRTC jitter buffer from stalling while waiting for an unresolvable sequence gap before hitting receiver timeout. Keeping the generation as an opaque pointer token enables lock-free pointer equality checks, preserving throughput across high-density SFU subscriber trees. |
boks1971
left a comment
There was a problem hiding this comment.
LGTM! One small code comment.
Also, ICE Restart does not do a receiver restart now. It is hard to get that alignment right between signalling and media. As media keeps flowing during an ICE restart and clients typically keep the sequence number contiguous, it is okay in practice. But, in theory it is possible that it can change.
Have to rely on restart detection to do that. Had some code for it, but it was not enabled by default because of fear of false negatives. Making some improvements to that path. Will observe that once that code goes in and can then rely on in-band detection for restarts.
| VideoLayer | ||
| Arrival int64 | ||
| ExtSequenceNumber uint64 | ||
| StreamGeneration *StreamGeneration // packet cache identity for GetPacketForStream |
There was a problem hiding this comment.
can we just make this an atomic counter?
There was a problem hiding this comment.
It now uses a process-wide atomic counter in the sfu: use an atomic counter for cache generations commit.
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
6f8d05f to
045ffb8
Compare
|
The update preserves the restart regression coverage while switching cache generations to an atomic counter. |
|
The description now omits ICE restart as a receiver-restart trigger. |
| if b.isClosed.Load() { | ||
| return 0, io.EOF | ||
| } | ||
| if generation == 0 || generation != b.streamGeneration { |
There was a problem hiding this comment.
One more thing.
Dropping 0 is okay I think, but there are tests that may have issues. There is one place in sfu/testutils/data.go. Maybe add a generation to those test packets? Or can accept 0 with the knowledge that the real packet path will never have it and only tests could have it.
There was a problem hiding this comment.
The sfu: give test packets a stream generation commit assigns generation 1 to shared test packets while retaining production rejection of generation 0.
Signed-off-by: Perfloop Agent <[email protected]>
If a receiver restarts (track-info resync or a detected discontinuity) while a NACK repair is in flight, reused source sequence numbers can pair old outgoing headers with new media. Carry the source cache generation through forwarding metadata and reject an obsolete read under the buffer’s existing read lock.
This retains the sequencer flushing from #4760 and covers snapshots already held by the worker. Cache identities distinguish buffer instances as well as resets. Media-backed probes use the same validation and retain their padding fallback. A packet copied before the restart can still be retransmitted unchanged.
TrackReceiver.ReadRTPgains astreamGenerationparameter,BufferProvidergainsGetPacketForStream, andExtPacketgainsStreamGeneration. The identity is auint64value from one process-wideatomic.Uint64counter.sequenceDiagram participant N as NACK worker participant D as DownTrack sequencer participant R as Receiver restart participant B as Packet buffer N->>D: Snapshot metadata and cache identity R->>B: Replace identity and resync R->>D: Flush sequencer N->>B: Read using snapshot identity B-->>N: Reject obsolete identitypkg/sfu/downtrack_restart_test.godrives the real receiver restart coordinator at four handoff schedules for NACKs and cached-media probes. It checks original media or a completed drop rather than relying on a timed absence assertion. Additional native tests cover repeated resets, different buffers, and identity propagation through RED and dummy receivers.Shared test packet fixtures now carry a nonzero stream generation; production cache reads still reject generation zero.
The focused Go race tests passed for forwarding, NACKs and probes, sequencer state, cache generations, RED readers, receiver wrappers, and the shared packet fixture users. Scoped golangci-lint reported no issues.
The schedules are bounded, not exhaustive interleaving coverage; overlap frequency in deployed traffic is unknown.
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.