Skip to content

sfu: don't reset a stream tracker that is unpaused while not paused - #5191

Merged
boks1971 merged 1 commit into
livekit:masterfrom
papazach:fix/stream-tracker-repeated-unpause
Nov 11, 2026
Merged

boks1971 merged 1 commit into
livekit:masterfrom
papazach:fix/stream-tracker-repeated-unpause

Conversation

@papazach

Copy link
Copy Markdown
Contributor

Since #4453, every track info update calls SetPaused(trackInfo.Muted) on a video track's stream trackers. StreamTracker.SetPaused(false) resets the tracker even when it was not paused.
As a result, updating an unmuted track's video size, codec info or simulcast layer SSRCs marked every live layer stopped, dropped it from the available layers, and zeroed its bitrate until the next bitrate report. SetPaused now returns early when the paused state does not change, matching StreamTrackerDependencyDescriptor.SetPaused.

Fixes #5190

Decisions

  • The guard is in StreamTracker.SetPaused rather than in StreamTrackerManager.UpdateTrackInfo. That way SetPaused is idempotent for every caller, and both StreamTrackerWorker implementations behave the same.
  • A new tracker starts unpaused and already in its reset state: the frame tracker's constructor calls Reset(), and the packet tracker's zero value equals its reset state. So AddTracker calling SetPaused(false) on a new tracker behaves as before.

Verification

  • go test ./pkg/sfu/streamtracker/ -run 'TestStreamTracker$' -race: the new stays active when unpaused while not paused subtest fails on master (expected: StreamStatusActive, actual: StreamStatusStopped) and passes with the fix. The new resets when unpaused after pause subtest passes before and after, which shows that a real unpause still resets the tracker.
  • go test ./pkg/sfu/streamtracker/ -race -count=3: passes.
  • go test ./pkg/sfu/... ./pkg/rtc/... -race: passes.
  • gofmt -s -l and go vet ./pkg/sfu/streamtracker/ ./pkg/sfu/: clean.
  • I also ran a StreamTrackerManager-level test, not included in this PR: an active layer followed by UpdateTrackInfo with an unmuted TrackInfo. It fails on master because the layer leaves GetLayeredBitrate's available layers, and it passes with the fix.

Since livekit#4453, StreamTrackerManager.UpdateTrackInfo calls
SetPaused(trackInfo.Muted) on every track info update, not only when
the mute state changes. StreamTracker.SetPaused(false) reset the tracker
even when it was not paused, so any track info update of an unmuted
video track (video size, codec info, simulcast layer SSRCs,
UpdateLocalVideoTrack) marked every live layer stopped, removed it from
the available layers, and zeroed its bitrate until the next packet and
bitrate report.

SetPaused now returns early when the paused state does not change, as
StreamTrackerDependencyDescriptor.SetPaused already does. A new tracker
starts unpaused in its reset state, so the SetPaused call in AddTracker
behaves the same.
@papazach
papazach requested a review from a team as a code owner November 11, 2026 17:57
@CLAassistant

CLAassistant commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@boks1971 boks1971 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.

Thank you for this! Really appreciate it.

@boks1971
boks1971 merged commit 7352c1d into livekit:master Nov 11, 2026
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track info updates on an unmuted video track reset its layer stream trackers

3 participants