Skip to content

Limit number of pending tracks per participant. - #4750

Merged
boks1971 merged 2 commits into
masterfrom
raja_pending_tracks
Aug 13, 2026
Merged

boks1971 merged 2 commits into
masterfrom
raja_pending_tracks

Conversation

@boks1971

Copy link
Copy Markdown
Contributor

Prevents just a signalling connection adding tracks without actually publishing them growing a large number.

Prevents just a signalling connection adding tracks without actually
publishing them growing a large number.
devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread pkg/rtc/participant.go
Comment on lines +2934 to +2945
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is acceptable. The cap on pending is high enough.

@boks1971
boks1971 merged commit 9d676e3 into master Aug 13, 2026
5 checks passed
@boks1971
boks1971 deleted the raja_pending_tracks branch August 13, 2026 11:18
pabloFuente added a commit to pabloFuente/livekit-server-sdk-dotnet that referenced this pull request Aug 27, 2026
It was broken because of hard limit on the number of pending tracks per participant
(added at livekit/livekit#4750)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants