Skip to content

rtc: release timed out pending tracks at the pending track limit - #4998

Merged
boks1971 merged 6 commits into
masterfrom
raja/reclaim-abandoned-pending-tracks
Oct 13, 2026
Merged

boks1971 merged 6 commits into
masterfrom
raja/reclaim-abandoned-pending-tracks

Conversation

@boks1971

@boks1971 boks1971 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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 AddTrack and 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 later AddTrack is 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.

Before this change
──────────────────
AddTrack ──► slot taken
             no media ever arrives
             client gives up (removes the transceiver)
                      │
                      ▼
             slot stays taken until the participant leaves   ◄── leak

   after 20 leaked slots: every AddTrack is rejected

The fix uses the supervisor, which already decides when a pending publish timed out. The server acts on it only at the limit.

After this change
─────────────────
cap of 20 reached ──► new AddTrack
                           │
                           ▼
             ask the supervisor which pending tracks timed out
             (publisher connected, track unmuted, no media for 30 s)
                           │
                           ▼
             release them: free the slot, tell the client
                           │
                           ▼
             new AddTrack takes a freed slot

Changes:

  • At the limit, release the pending tracks that the supervisor reports as timed out. A live track never reports a timeout, so a track queued behind it is safe. This uses the release logic from rtc: release pending tracks that never receive media #4971.
  • Restart the timeout when a queued track reaches the front of the queue. Before, it kept the clock of the track ahead of it and timed out at once. This also removes a false publication error in the logs for queued tracks, or a false full reconnect when reconnect_on_publication_error is on. That fix applies below the limit too.
  • Fix a data race: checkPublications wrote the error field under the read lock.
  • Drop late media for a released track. When no pending track matches incoming media, the server picks the first pending track of the same type, so late media could take another track's identity. Release now records the track's signal and SDP client ids, the 32 most recent. Media or an offer for those ids is dropped. A new AddTrack that 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 AddTrack after 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

boks1971 and others added 3 commits October 13, 2026 13:30
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]>
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]>
@boks1971 boks1971 changed the title rtc: reclaim abandoned pending tracks so long-lived publishers do not get stuck rtc: release timed out pending tracks at the pending track limit Oct 13, 2026
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]>
@boks1971
boks1971 marked this pull request as ready for review October 13, 2026 09:17
@boks1971
boks1971 requested a review from a team as a code owner October 13, 2026 09:17

@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 2 potential issues.

Devin Review

Comment thread pkg/rtc/participant.go
Comment on lines +2992 to +2995
pti.trackInfos = remaining
if len(pti.trackInfos) == 0 {
delete(p.pendingTracks, cid)
}

@devin-ai-integration devin-ai-integration Bot Oct 13, 2026 •

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.

🔴 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.

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.

Using a tombstone to reject late publications.

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.

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.

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.

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.

Comment on lines +139 to +140
if pm.err != nil && pm.opMon.Check() != nil {
trackIDs = append(trackIDs, trackID)

@devin-ai-integration devin-ai-integration Bot Oct 13, 2026 •

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.

🔴 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.

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.

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 AddTrack comes in at that time

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.

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.

boks1971 and others added 2 commits October 13, 2026 15:57
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]>
@boks1971
boks1971 merged commit 308554d into master Oct 13, 2026
5 checks passed
@boks1971
boks1971 deleted the raja/reclaim-abandoned-pending-tracks branch October 13, 2026 11:10
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request Oct 14, 2026
…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 ([#&#8203;4987](livekit/livekit#4987))
- sfu: keep VP8 descriptor frame numbers across migration ([#&#8203;4989](livekit/livekit#4989))
- sfu: filter VP9 and AV1 simulcast temporal layers with the dependency descriptor ([#&#8203;4991](livekit/livekit#4991))
- sfu: filter VP8 temporal layers by frame when the dependency descriptor is sent ([#&#8203;4976](livekit/livekit#4976))
- sfu: switch VP8 temporal layers up with the dependency descriptor ([#&#8203;4974](livekit/livekit#4974))
- sfu: pad the slot of a filtered packet that follows a sequence number gap ([#&#8203;4983](livekit/livekit#4983))
- sfu: send padding in the slot of a dropped out-of-order packet ([#&#8203;4979](livekit/livekit#4979))
- sfu: parse VP8 and VP9 payload descriptors without an allocation ([#&#8203;4981](livekit/livekit#4981))
- DownTrack: arm key frame requester timer only while a layer lock is pending ([#&#8203;4980](livekit/livekit#4980))
- turn: refuse TCP relays and limit relays to this host to media ports ([#&#8203;4992](livekit/livekit#4992))
- agent endpoints: address an unnamed deployment as "\_" ([#&#8203;4997](livekit/livekit#4997))
- Add OSS Scanner build image and threat model ([#&#8203;4995](livekit/livekit#4995))
- Update golang Docker tag to v1.27.1 ([#&#8203;4985](livekit/livekit#4985))
- Update alpine Docker tag to v3.24.2 ([#&#8203;4984](livekit/livekit#4984))
- Update module github.com/maxbrunsfeld/counterfeiter/v6 to v6.13.0 ([#&#8203;4915](livekit/livekit#4915))

##### Fixed

- Send NACKs when processing RTX packets ([#&#8203;5000](livekit/livekit#5000))
- sfu: send padding-only packets with no payload ([#&#8203;4993](livekit/livekit#4993))
- rtc: release timed out pending tracks at the pending track limit ([#&#8203;4998](livekit/livekit#4998))
- Fix nil pointer dereference in IOInfoService.UpdateIngressState ([#&#8203;4806](livekit/livekit#4806))
- rtc: keep update cache eviction order when listing recent disconnects ([#&#8203;4975](livekit/livekit#4975))
- fix(cli): return non-zero exit status on command errors ([#&#8203;4888](livekit/livekit#4888))
- Disable AV1 for Firefox clients before 157 ([#&#8203;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
hbjydev pushed a commit to hbjydev/phoebe that referenced this pull request Oct 20, 2026
…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 ([#&#8203;4987](livekit/livekit#4987))
- sfu: keep VP8 descriptor frame numbers across migration ([#&#8203;4989](livekit/livekit#4989))
- sfu: filter VP9 and AV1 simulcast temporal layers with the dependency descriptor ([#&#8203;4991](livekit/livekit#4991))
- sfu: filter VP8 temporal layers by frame when the dependency descriptor is sent ([#&#8203;4976](livekit/livekit#4976))
- sfu: switch VP8 temporal layers up with the dependency descriptor ([#&#8203;4974](livekit/livekit#4974))
- sfu: pad the slot of a filtered packet that follows a sequence number gap ([#&#8203;4983](livekit/livekit#4983))
- sfu: send padding in the slot of a dropped out-of-order packet ([#&#8203;4979](livekit/livekit#4979))
- sfu: parse VP8 and VP9 payload descriptors without an allocation ([#&#8203;4981](livekit/livekit#4981))
- DownTrack: arm key frame requester timer only while a layer lock is pending ([#&#8203;4980](livekit/livekit#4980))
- turn: refuse TCP relays and limit relays to this host to media ports ([#&#8203;4992](livekit/livekit#4992))
- agent endpoints: address an unnamed deployment as "\_" ([#&#8203;4997](livekit/livekit#4997))
- Add OSS Scanner build image and threat model ([#&#8203;4995](livekit/livekit#4995))
- Update golang Docker tag to v1.27.1 ([#&#8203;4985](livekit/livekit#4985))
- Update alpine Docker tag to v3.24.2 ([#&#8203;4984](livekit/livekit#4984))
- Update module github.com/maxbrunsfeld/counterfeiter/v6 to v6.13.0 ([#&#8203;4915](livekit/livekit#4915))

##### Fixed

- Send NACKs when processing RTX packets ([#&#8203;5000](livekit/livekit#5000))
- sfu: send padding-only packets with no payload ([#&#8203;4993](livekit/livekit#4993))
- rtc: release timed out pending tracks at the pending track limit ([#&#8203;4998](livekit/livekit#4998))
- Fix nil pointer dereference in IOInfoService.UpdateIngressState ([#&#8203;4806](livekit/livekit#4806))
- rtc: keep update cache eviction order when listing recent disconnects ([#&#8203;4975](livekit/livekit#4975))
- fix(cli): return non-zero exit status on command errors ([#&#8203;4888](livekit/livekit#4888))
- Disable AV1 for Firefox clients before 157 ([#&#8203;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
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.

Abandoned pending tracks are never released, so long-lived participants permanently hit too many pending tracks

2 participants