Repository navigation
Limit number of pending tracks per participant. - #4750
Conversation
Prevents just a signalling connection adding tracks without actually publishing them growing a large number.
| if len(p.pendingTracks) >= cMaxPendingTracks { | ||
| p.pubLogger.Infow("too many pending tracks, rejecting new track", "numPendingTracks", len(p.pendingTracks)) | ||
| p.sendRequestResponse(&livekit.RequestResponse{ | ||
| Reason: livekit.RequestResponse_LIMIT_EXCEEDED, | ||
| Message: fmt.Sprintf("too many pending tracks, rejecting new track, numPendingTracks: %d", len(p.pendingTracks)), | ||
| Request: &livekit.RequestResponse_AddTrack{ | ||
| AddTrack: utils.CloneProto(req), | ||
| }, | ||
| }) | ||
| p.pendingTracksLock.Unlock() | ||
| return nil | ||
| } |
There was a problem hiding this comment.
🟡 Publishing a replacement for an already-known track can be refused once the pending list is full
New publish requests are refused (len(p.pendingTracks) >= cMaxPendingTracks at pkg/rtc/participant.go:2934) before checking whether the request is just a follow-up for a track the participant already registered, so ordinary re-publishing of an existing track is blocked even though it would add nothing new.
Impact: A participant that has reached the pending-track cap cannot re-publish or replace tracks it already announced, and those publish attempts silently fail.
Why the cap is applied to requests that do not grow the pending map
The cap is evaluated at the very top of addPendingTrack (pkg/rtc/participant.go:2934-2945), before the branch at pkg/rtc/participant.go:3112 that handles the case where req.Cid already has a pending entry (or a published track with the same signal cid). In that branch the request is either appended to the existing pendingTrackInfo.trackInfos (map size unchanged) or replaces an entry for a currently published track. Those flows do not increase the number of distinct pending cids, so the abuse the cap targets (unbounded growth from signalling-only clients) does not apply to them, yet they are rejected with LIMIT_EXCEEDED. Since pending entries are only removed when a track actually gets published (pkg/rtc/participant.go:3524-3526) and never expire, a participant stuck at the cap can never re-publish an existing track. Moving the cap check to just before the final p.pendingTracks[req.Cid] = pti at pkg/rtc/participant.go:3169 (i.e. only for genuinely new cids) would preserve the intent.
Prompt for agents
In pkg/rtc/participant.go addPendingTrack, the cMaxPendingTracks cap is checked at the top of the function, before the code determines whether the request corresponds to an already-pending cid or an already-published track with the same signal cid (the branch guarded by getPublishedTrackBySignalCid/getPublishedTrackBySdpCid/pendingTracks[req.Cid]). Those paths do not add a new key to the pendingTracks map (the queued path only appends to an existing entry, which is already bounded by cMaxPendingQueuedTracks), so applying the global cap there rejects legitimate re-publish/queued requests. Consider evaluating the cMaxPendingTracks limit only on the path that inserts a brand new pendingTracks key, so the cap bounds the number of distinct pending cids as intended.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
this is acceptable. The cap on pending is high enough.
It was broken because of hard limit on the number of pending tracks per participant (added at livekit/livekit#4750)
Prevents just a signalling connection adding tracks without actually publishing them growing a large number.