Repository navigation
rtc: release timed out pending tracks at the pending track limit - #4998
Conversation
A pending track is freed only when its first media arrives or the participant leaves. A client that calls AddTrack and then gives up before any media flows leaves the slot held for the whole session. After 20 such slots, every later AddTrack is rejected. Reclaim these slots when the cap is hit, if no media arrived and the slot is older than the publish timeout. Keep the supervisor monitor in step for queued tracks that share a track id. Add a publish_timeout config value, default 30s. Fixes: #4970 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Replace the createdAt sweep with the supervisor's publish timeout. The supervisor counts time only while the publisher is connected and the track is unmuted, and never reports a live track, so a successor queued behind a live track is not released. Restart the publish timer when a queued publish reaches the front of the queue, so it does not inherit the clock of the track ahead of it. Write the publication error under the write lock, since it is now read from another goroutine. Drop the publish_timeout config value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TimedOutPublications re-checks the monitor, because the cached error is cleared only on the next tick. A track that published since is not reported, so its queued successor is not released. RemovePublication keeps a monitor that still holds a published track. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| pti.trackInfos = remaining | ||
| if len(pti.trackInfos) == 0 { | ||
| delete(p.pendingTracks, cid) | ||
| } |
There was a problem hiding this comment.
🔴 Republished tracks lose their SDP media
When a client republishes a released track with its old SDP ID, addPendingTrack clears only its signal ID. populateSdpCid skips the offer, and mediaTrackReceived drops its media, so the new track never publishes.
Learn more
A pending track stores its signal CID and can acquire a distinct SDP CID when an offer arrives in populateSdpCid. Releasing it records both identifiers. A later AddTrack using the same signal CID clears only that identifier; if its offer retains the old SDP CID, populateSdpCid ignores the offer and mediaTrackReceived ignores its media. A fresh request can also use a formerly released CID as a simulcast codec CID.
Example: Release a video track with signal CID camera and SDP CID firefox-track. Re-add camera and offer firefox-track; the new track gets a pending slot but cannot publish its media.
Recommended fix: When accepting an AddTrack, clear tombstones for identifiers belonging to its new publication, including simulcast codec CIDs; handle reused SDP CIDs when resolving the new offer without allowing unrelated late media to claim a different track.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Using a tombstone to reject late publications.
There was a problem hiding this comment.
From Devin
Suggested fix
The tombstone still blocks late media from a released track. On a deliberate republish, it now clears everything that belonged to the released track:
On release, the track's codec and SDP CIDs are stored under its signal CID (releasedTrackCidGroups).
On AddTrack with that signal CID, the signal CID, its SDP and codec CIDs, and the request's simulcast codec CIDs are all removed from the tombstone list.
When a signal CID ages out of the 32-entry list, its group is removed too, so the map stays bounded.
As a result, a Firefox client that reuses a transceiver gets its offer matched by populateSdpCid and its media accepted by mediaTrackReceived. The test now also checks that sdpA is cleared after cidA is re-added.
There was a problem hiding this comment.
From a chat with Devin
Fixed in 62059a8: tombstones are now grouped per released track (signal, codec and SDP CIDs), and an AddTrack that reuses any of the request's signal or simulcast codec CIDs clears the whole group, including the old SDP ID a reused transceiver keeps. The list is bounded per track, and tests cover the SDP and codec-CID reuse cases.
| if pm.err != nil && pm.opMon.Check() != nil { | ||
| trackIDs = append(trackIDs, trackID) |
There was a problem hiding this comment.
🔴 Publisher disconnect evicts pending tracks
After a publisher disconnects with unmuted pending tracks, TimedOutPublications still treats their running clocks as publish timeouts. A new AddTrack at the limit removes those tracks despite the publisher's inability to send media.
Learn more
The supervisor starts a publish clock when an unmuted publisher is connected. setConnected does not clear that clock on disconnect, and Check does not check connection state. This new timeout query therefore exposes a disconnected publisher's pending tracks to eviction at capacity, even though they cannot send media until reconnection. Existing timeout logging during the disconnect does not protect the pending entries.
Example: A publisher connects with 20 pending unmuted tracks, then loses its publisher peer connection for 31 seconds. Its next AddTrack at the limit removes the old tracks, even if they are waiting to resume publishing.
Recommended fix: Make PublicationMonitor.Check or TimedOutPublications require an actively connected publisher for release, and re-arm the pending publish window when that connection returns. Validate the connected-to-disconnected-to-connected case with a pending publish.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Not handling this intentionally as this is a really edge case
- 20 tracks queued, none publishing
- Disconnect happens, but does not go to ICE failed
- An
AddTrackcomes in at that time
There was a problem hiding this comment.
In chat with Devin, got this agreement
Agreed this is pre-existing (it already surfaces as a false publication error today), and it needs the pending limit, never-published unmuted tracks, a long publisher disconnect, and an AddTrack all at once. Released tracks get TrackUnpublished, so clients can republish. Deferring to a follow-up that wires the transport's connection state into the supervisor and restarts the publish window on reconnect.
Media or an offer with no matching pending track falls back to the first pending track of the same type. After a release, late media for the released track could take another pending track's identity. Record the released track's signal and SDP client ids, the 32 most recent, and drop media or offers for them. An AddTrack that reuses the client id clears it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A re-add cleared only the signal client id, so a Firefox republish that keeps the old SDP id had its offer and media dropped. Keep the ids of each released track together, and clear the whole track when a new AddTrack reuses its signal or simulcast codec client id. The limit now counts released tracks, and a track ages out with all of its ids. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…9 ➔ v1.13.10) (#2338) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [docker.io/livekit/livekit-server](https://github.com/livekit/livekit) | patch | `v1.13.9` → `v1.13.10` | --- ### Release Notes <details> <summary>livekit/livekit (docker.io/livekit/livekit-server)</summary> ### [`v1.13.10`](https://github.com/livekit/livekit/releases/tag/v1.13.10) [Compare Source](livekit/livekit@v1.13.9...v1.13.10) ##### Changed - sfu: forward the dependency descriptor for VP8 simulcast ([#​4987](livekit/livekit#4987)) - sfu: keep VP8 descriptor frame numbers across migration ([#​4989](livekit/livekit#4989)) - sfu: filter VP9 and AV1 simulcast temporal layers with the dependency descriptor ([#​4991](livekit/livekit#4991)) - sfu: filter VP8 temporal layers by frame when the dependency descriptor is sent ([#​4976](livekit/livekit#4976)) - sfu: switch VP8 temporal layers up with the dependency descriptor ([#​4974](livekit/livekit#4974)) - sfu: pad the slot of a filtered packet that follows a sequence number gap ([#​4983](livekit/livekit#4983)) - sfu: send padding in the slot of a dropped out-of-order packet ([#​4979](livekit/livekit#4979)) - sfu: parse VP8 and VP9 payload descriptors without an allocation ([#​4981](livekit/livekit#4981)) - DownTrack: arm key frame requester timer only while a layer lock is pending ([#​4980](livekit/livekit#4980)) - turn: refuse TCP relays and limit relays to this host to media ports ([#​4992](livekit/livekit#4992)) - agent endpoints: address an unnamed deployment as "\_" ([#​4997](livekit/livekit#4997)) - Add OSS Scanner build image and threat model ([#​4995](livekit/livekit#4995)) - Update golang Docker tag to v1.27.1 ([#​4985](livekit/livekit#4985)) - Update alpine Docker tag to v3.24.2 ([#​4984](livekit/livekit#4984)) - Update module github.com/maxbrunsfeld/counterfeiter/v6 to v6.13.0 ([#​4915](livekit/livekit#4915)) ##### Fixed - Send NACKs when processing RTX packets ([#​5000](livekit/livekit#5000)) - sfu: send padding-only packets with no payload ([#​4993](livekit/livekit#4993)) - rtc: release timed out pending tracks at the pending track limit ([#​4998](livekit/livekit#4998)) - Fix nil pointer dereference in IOInfoService.UpdateIngressState ([#​4806](livekit/livekit#4806)) - rtc: keep update cache eviction order when listing recent disconnects ([#​4975](livekit/livekit#4975)) - fix(cli): return non-zero exit status on command errors ([#​4888](livekit/livekit#4888)) - Disable AV1 for Firefox clients before 157 ([#​4962](livekit/livekit#4962)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNTEuMiIsInVwZGF0ZWRJblZlciI6IjQ0LjE1MS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/2338
…v1.13.10) (#884) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [docker.io/livekit/livekit-server](https://github.com/livekit/livekit) | patch | `v1.13.9` → `v1.13.10` | --- ### Release Notes <details> <summary>livekit/livekit (docker.io/livekit/livekit-server)</summary> ### [`v1.13.10`](https://github.com/livekit/livekit/releases/tag/v1.13.10) [Compare Source](livekit/livekit@v1.13.9...v1.13.10) ##### Changed - sfu: forward the dependency descriptor for VP8 simulcast ([#​4987](livekit/livekit#4987)) - sfu: keep VP8 descriptor frame numbers across migration ([#​4989](livekit/livekit#4989)) - sfu: filter VP9 and AV1 simulcast temporal layers with the dependency descriptor ([#​4991](livekit/livekit#4991)) - sfu: filter VP8 temporal layers by frame when the dependency descriptor is sent ([#​4976](livekit/livekit#4976)) - sfu: switch VP8 temporal layers up with the dependency descriptor ([#​4974](livekit/livekit#4974)) - sfu: pad the slot of a filtered packet that follows a sequence number gap ([#​4983](livekit/livekit#4983)) - sfu: send padding in the slot of a dropped out-of-order packet ([#​4979](livekit/livekit#4979)) - sfu: parse VP8 and VP9 payload descriptors without an allocation ([#​4981](livekit/livekit#4981)) - DownTrack: arm key frame requester timer only while a layer lock is pending ([#​4980](livekit/livekit#4980)) - turn: refuse TCP relays and limit relays to this host to media ports ([#​4992](livekit/livekit#4992)) - agent endpoints: address an unnamed deployment as "\_" ([#​4997](livekit/livekit#4997)) - Add OSS Scanner build image and threat model ([#​4995](livekit/livekit#4995)) - Update golang Docker tag to v1.27.1 ([#​4985](livekit/livekit#4985)) - Update alpine Docker tag to v3.24.2 ([#​4984](livekit/livekit#4984)) - Update module github.com/maxbrunsfeld/counterfeiter/v6 to v6.13.0 ([#​4915](livekit/livekit#4915)) ##### Fixed - Send NACKs when processing RTX packets ([#​5000](livekit/livekit#5000)) - sfu: send padding-only packets with no payload ([#​4993](livekit/livekit#4993)) - rtc: release timed out pending tracks at the pending track limit ([#​4998](livekit/livekit#4998)) - Fix nil pointer dereference in IOInfoService.UpdateIngressState ([#​4806](livekit/livekit#4806)) - rtc: keep update cache eviction order when listing recent disconnects ([#​4975](livekit/livekit#4975)) - fix(cli): return non-zero exit status on command errors ([#​4888](livekit/livekit#4888)) - Disable AV1 for Firefox clients before 157 ([#​4962](livekit/livekit#4962)) </details> --- ### Configuration 📅 **Schedule**: (in timezone Europe/London) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNjcuNSIsInVwZGF0ZWRJblZlciI6IjQ0LjE2Ny41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.hayden.moe/hayden/phoebe/pulls/884
A participant can hold at most 20 pending tracks. A pending track is made by
AddTrack. Today it is freed in only two cases: when its first media arrives, or when the participant leaves the room.If a client calls
AddTrackand then gives up before any media flows, nothing frees the slot. Some clients give up by removing the transceiver and renegotiating. The server gets no signal it acts on. The slot stays taken for the whole session. After 20 such slots, every laterAddTrackis rejected, even for tracks that would carry media. The participant must reconnect to recover. This hits long-lived publishers that add and drop tracks over many hours.The fix uses the supervisor, which already decides when a pending publish timed out. The server acts on it only at the limit.
Changes:
reconnect_on_publication_erroris on. That fix applies below the limit too.checkPublicationswrote the error field under the read lock.AddTrackthat reuses any of the track's ids clears all of them.Tests: supervisor tests with real events, one subtest per queue case; participant tests for releasing a lone track and a queued pair, and for dropping late media of a released track. All pass with
-race.State: no change below the limit. With the supervisor disabled, nothing is released, as today. Migrated pending tracks are monitored too, so at the limit one can lose its slot after 30 s with no media.
Firefox uses a different SDP id than the signal id. If a track is released before any offer carried it, there is no SDP id to record, and a later offer for it is still matched by type. That is the existing Firefox type guess, and a track that no offer ever carried sends no media.
The supervisor does not track a publisher disconnect, so pending tracks keep their publish clock through one. At the limit, the first
AddTrackafter the connection returns can release tracks that timed out during the gap. Before this change that was already a false publication error. Wiring the transport's connection state into the supervisor fixes it, and it is left out to keep this change small.Fixes: #4970
🤖 Generated with Claude Code