Repository navigation
rtc: release pending tracks that never receive media - #4971
kevin-pan-skydio wants to merge 1 commit into
Conversation
A pending track is only removed from pendingTracks when its first RTP arrives or the participant closes. If a client abandons a publish (AddTrack followed by removing the transceiver before any media flows), there is no signal the server acts on, so the entry is held for the rest of the session. Long-lived publishers that churn tracks eventually hit cMaxPendingTracks and every subsequent AddTrack is rejected with "too many pending tracks". The participant supervisor already detects this case: it reports "publish time out" after 30s of a connected, unmuted publication with no media. When ReconnectOnPublicationError is not set, that error was only logged. Now the participant drops the pending track, removes its supervisor monitor, and tells the client the track is unpublished. The full-reconnect behavior is unchanged when the option is enabled. Fixes: livekit#4970
| for _, ti := range pti.trackInfos { | ||
| if livekit.TrackID(ti.Sid) == trackID { | ||
| released = ti | ||
| continue | ||
| } | ||
| remaining = append(remaining, ti) | ||
| } | ||
| pti.trackInfos = remaining | ||
| if len(pti.trackInfos) == 0 { | ||
| delete(p.pendingTracks, cid) |
There was a problem hiding this comment.
🔴 Queued publishes vanish on timeout
When a CID has queued publishes, releasePendingTrack deletes every entry sharing the timed-out SID. setTrackID reuses that SID for queued requests, so those publishes never get their turn.
Learn more
A pending track keeps multiple publish requests in trackInfos when the same CID is added again. setTrackID assigns each request the first entry's SID. addMediaTrack normally consumes only the first entry and keeps the remaining requests queued. Removing every matching SID instead discards requests that have not yet been attempted.
Example: A client calls AddTrack twice with CID camera, producing two pending entries with SID TR_1. The first publish times out. Both entries are deleted, even though the second request was queued to publish afterward.
Recommended fix: Retire only the timed-out request and preserve or explicitly cancel and notify each queued request. Update the queue state and supervisor monitoring so that a surviving request can proceed after the first is removed.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if p.ProtocolVersion().SupportsUnpublish() { | ||
| p.sendTrackUnpublished(trackID) | ||
| } else { | ||
| p.sendTrackMuted(trackID, true) |
There was a problem hiding this comment.
🔴 Late timeout unpublishes a live track
If media arrives after checkPublications reports a timeout, releasePendingTrack can find a queued request sharing the published SID. It deletes that request and sends TrackUnpublished for the live track, stopping the client's active publication.
Learn more
The supervisor checkPublications collects timeout IDs before invoking the participant callback. Meanwhile, addMediaTrack can publish the first request and retain later requests under the same CID and SID. A delayed timeout callback sees those queued entries and mistakes the SID for an unpublished track. The resulting unpublish signal targets a published track.
Example: Two requests for CID camera share SID TR_1. The supervisor checks just before media publishes the first request. When its callback runs afterward, the second request remains pending, so the server sends TrackUnpublished for TR_1 despite the live first publish.
Recommended fix: Validate that the timed-out publication still corresponds to the current pending request, and that its SID is not published, before sending an unpublish signal. Coordinate this decision with pending-track and supervisor state across the check/callback boundary.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Closing this issue now |
A pending track is only removed from pendingTracks when its first RTP arrives or the participant closes. If a client abandons a publish (AddTrack followed by removing the transceiver before any media flows), there is no signal the server acts on, so the entry is held for the rest of the session. Long-lived publishers that churn tracks eventually hit cMaxPendingTracks and every subsequent AddTrack is rejected with "too many pending tracks".
The participant supervisor already detects this case: it reports "publish time out" after 30s of a connected, unmuted publication with no media. When ReconnectOnPublicationError is not set, that error was only logged. Now the participant drops the pending track, removes its supervisor monitor, and tells the client the track is unpublished. The full-reconnect behavior is unchanged when the option is enabled.
Fixes: #4970