Skip to content

Fix two flaky assertions in the subscription manager tests - #4803

Merged
boks1971 merged 1 commit into
livekit:masterfrom
feldgendler:alex/unsubscribe-test-flake
Aug 27, 2026
Merged

boks1971 merged 1 commit into
livekit:masterfrom
feldgendler:alex/unsubscribe-test-flake

Conversation

@feldgendler

Copy link
Copy Markdown
Contributor

Problem

TestUnsubscribe fails intermittently in CI at pkg/rtc/subscriptionmanager_test.go:251:

❌ TestUnsubscribe (0s)
    Error Trace: pkg/rtc/subscriptionmanager_test.go:251
    Error:       Should be false
    Test:        TestUnsubscribe

UnsubscribeFromTrack → setDesired(trackID, false) clears the notifiers under s.lock, and setChangedNotifierLocked hands the removal to a goroutine of its own:

if existing != nil {
	go existing.RemoveObserver(string(s.subscriberID))
}

The require.Eventually above the assertion waits for needsUnsubscribe, pendingUnsubscribes and the subscription map — none of which order against that goroutine — so HasObservers() can be read before it runs.

TestSubscribe/happy path subscribe has the same defect at line 116: it waits for numParticipantSubscribed to reach 2 and then reads numParticipantUnsubscribed directly, while unmarkSubscribedTo delivers that callback with a bare go changedCB(publisherID, false). The subscribed one, in markSubscribedTo, is called inline.

Fix

Wait for each of them, each with a message of its own rather than folded into an existing condition, so that a leak which is real still reports which invariant broke.

The go in setChangedNotifierLocked is left alone: it arrived in #1429 along with the *Locked refactor, to avoid holding trackSubscription.lock across the notifier's lock. Quieting a test is not a reason to reopen that.

Testing

Both windows are microseconds wide and do not reproduce by repetition — 200 runs of TestUnsubscribe with -race, 8 concurrent runs of 50, and 300 runs at -cpu=1 all pass either way. Forcing them with go test -overlay (a 50ms sleep before each of the two calls, leaving the tree untouched) reproduces both exactly as CI reports them — line 251 Should be false, and line 116 expected: 1 / actual: 0 — and both pass 30/30 with this change under the same delays. go test -race ./pkg/rtc/ passes.

🤖 Generated with Claude Code

TestUnsubscribe checked that the changed-notifier observer was gone as
soon as the unsubscribe had settled, but setDesired leaves the
RemoveObserver call to a goroutine of its own and nothing the test waits
on orders against it, so CI caught the assertion running first.
TestSubscribe has the same defect on the unsubscribed callback, which
unmarkSubscribedTo delivers with a bare go while the subscribed one is
called inline.

Wait for both, each with a message of its own, so that a leak that is
real still says which of them broke.

Co-Authored-By: Claude Opus 5 <[email protected]>

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

Open in Devin Review

@boks1971

Copy link
Copy Markdown
Contributor

Thank you for this!

@boks1971
boks1971 merged commit dc2bd1d into livekit:master Aug 27, 2026
1 of 4 checks passed
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request Sep 14, 2026
…6 ➔ v1.13.7) (#2108)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker.io/livekit/livekit-server](https://github.com/livekit/livekit) | patch | `v1.13.6` → `v1.13.7` |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/567) for more information.

---

### Release Notes

<details>
<summary>livekit/livekit (docker.io/livekit/livekit-server)</summary>

### [`v1.13.7`](https://github.com/livekit/livekit/releases/tag/v1.13.7)

[Compare Source](livekit/livekit@v1.13.6...v1.13.7)

##### Added

- Participant kind agent details ([#&#8203;4809](livekit/livekit#4809))
- report a reason on room-ended telemetry ([#&#8203;4815](livekit/livekit#4815))
- telemetry: support roomID change for a participant ([#&#8203;4816](livekit/livekit#4816))
- log telemetry guard details ([#&#8203;4817](livekit/livekit#4817))
- ingress: add opt-in support for udp\:// URL pull ingress ([#&#8203;4810](livekit/livekit#4810))
- Support VP9/AV1 simulcast ([#&#8203;4830](livekit/livekit#4830))
- add test-server support for compressed join requests ([#&#8203;4834](livekit/livekit#4834))
- wire psrpc bus compression into the message bus constructor ([#&#8203;4844](livekit/livekit#4844))
- turn: accept PROXY protocol on the TCP listener ([#&#8203;4852](livekit/livekit#4852))
- telemetry: add visibility into stats worker reference underflow ([#&#8203;4856](livekit/livekit#4856))
- rtc: add GetSubscribedDataTracks to LocalParticipant ([#&#8203;4862](livekit/livekit#4862))

##### Changed

- Skip the docker-backed service tests when there is no docker ([#&#8203;4799](livekit/livekit#4799))
- Wait for the callbacks these tests assert on. ([#&#8203;4803](livekit/livekit#4803))
- utils: make Median generic, overflow-safe, and add tests ([#&#8203;4553](livekit/livekit#4553))
- warp log ([#&#8203;4811](livekit/livekit#4811))
- Remove duplication within cpuload and sysload ([#&#8203;4818](livekit/livekit#4818))
- Update github.com/livekit/protocol digest to [`a469dd4`](livekit/livekit@a469dd4) ([#&#8203;4820](livekit/livekit#4820))
- update ice fork for warp ([#&#8203;4824](livekit/livekit#4824))
- Move data track packet serialization to protocol ([#&#8203;4829](livekit/livekit#4829))
- Update README to include snippet about Agents ([#&#8203;4808](livekit/livekit#4808))
- protocol update for SDP unmarshal hardening ([#&#8203;4836](livekit/livekit#4836))
- Update golang Docker tag to v1.26.7 ([#&#8203;4846](livekit/livekit#4846))
- README rewrite ([#&#8203;4837](livekit/livekit#4837))

##### Fixed

- Set up track info properly for dummy receiver. ([#&#8203;4807](livekit/livekit#4807))
- Do not escape the ICE server URI in the WHIP Link header ([#&#8203;4795](livekit/livekit#4795))
- fix: hold signal messages until the ReconnectResponse goes out ([#&#8203;4827](livekit/livekit#4827))
- Fix/reconcile data track subscription deadlock ([#&#8203;4843](livekit/livekit#4843))
- telemetry: drop unused getCPUStats, unblocking darwin builds without cgo ([#&#8203;4841](livekit/livekit#4841))
- update psrpc for subscription close goroutine leak fix ([#&#8203;4859](livekit/livekit#4859))
- telemetry: do not recreate a stats worker for a released guard ([#&#8203;4860](livekit/livekit#4860))
- Get participant by authed identity in WHIP participant service. ([#&#8203;4861](livekit/livekit#4861))

</details>

---

### Configuration

📅 **Schedule**: (in timezone Europe/Paris)

- 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:eyJjcmVhdGVkSW5WZXIiOiI0NC44My4xIiwidXBkYXRlZEluVmVyIjoiNDQuODMuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicmVub3ZhdGUvY29udGFpbmVyIiwidHlwZS9wYXRjaCJdfQ==-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/2108
hbjydev pushed a commit to hbjydev/phoebe that referenced this pull request Sep 14, 2026
…6 → v1.13.7) (#611)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker.io/livekit/livekit-server](https://github.com/livekit/livekit) | patch | `v1.13.6` → `v1.13.7` |

---

### Release Notes

<details>
<summary>livekit/livekit (docker.io/livekit/livekit-server)</summary>

### [`v1.13.7`](https://github.com/livekit/livekit/releases/tag/v1.13.7)

[Compare Source](livekit/livekit@v1.13.6...v1.13.7)

##### Added

- Participant kind agent details ([#&#8203;4809](livekit/livekit#4809))
- report a reason on room-ended telemetry ([#&#8203;4815](livekit/livekit#4815))
- telemetry: support roomID change for a participant ([#&#8203;4816](livekit/livekit#4816))
- log telemetry guard details ([#&#8203;4817](livekit/livekit#4817))
- ingress: add opt-in support for udp\:// URL pull ingress ([#&#8203;4810](livekit/livekit#4810))
- Support VP9/AV1 simulcast ([#&#8203;4830](livekit/livekit#4830))
- add test-server support for compressed join requests ([#&#8203;4834](livekit/livekit#4834))
- wire psrpc bus compression into the message bus constructor ([#&#8203;4844](livekit/livekit#4844))
- turn: accept PROXY protocol on the TCP listener ([#&#8203;4852](livekit/livekit#4852))
- telemetry: add visibility into stats worker reference underflow ([#&#8203;4856](livekit/livekit#4856))
- rtc: add GetSubscribedDataTracks to LocalParticipant ([#&#8203;4862](livekit/livekit#4862))

##### Changed

- Skip the docker-backed service tests when there is no docker ([#&#8203;4799](livekit/livekit#4799))
- Wait for the callbacks these tests assert on. ([#&#8203;4803](livekit/livekit#4803))
- utils: make Median generic, overflow-safe, and add tests ([#&#8203;4553](livekit/livekit#4553))
- warp log ([#&#8203;4811](livekit/livekit#4811))
- Remove duplication within cpuload and sysload ([#&#8203;4818](livekit/livekit#4818))
- Update github.com/livekit/protocol digest to [`a469dd4`](livekit/livekit@a469dd4) ([#&#8203;4820](livekit/livekit#4820))
- update ice fork for warp ([#&#8203;4824](livekit/livekit#4824))
- Move data track packet serialization to protocol ([#&#8203;4829](livekit/livekit#4829))
- Update README to include snippet about Agents ([#&#8203;4808](livekit/livekit#4808))
- protocol update for SDP unmarshal hardening ([#&#8203;4836](livekit/livekit#4836))
- Update golang Docker tag to v1.26.7 ([#&#8203;4846](livekit/livekit#4846))
- README rewrite ([#&#8203;4837](livekit/livekit#4837))

##### Fixed

- Set up track info properly for dummy receiver. ([#&#8203;4807](livekit/livekit#4807))
- Do not escape the ICE server URI in the WHIP Link header ([#&#8203;4795](livekit/livekit#4795))
- fix: hold signal messages until the ReconnectResponse goes out ([#&#8203;4827](livekit/livekit#4827))
- Fix/reconcile data track subscription deadlock ([#&#8203;4843](livekit/livekit#4843))
- telemetry: drop unused getCPUStats, unblocking darwin builds without cgo ([#&#8203;4841](livekit/livekit#4841))
- update psrpc for subscription close goroutine leak fix ([#&#8203;4859](livekit/livekit#4859))
- telemetry: do not recreate a stats worker for a released guard ([#&#8203;4860](livekit/livekit#4860))
- Get participant by authed identity in WHIP participant service. ([#&#8203;4861](livekit/livekit#4861))

</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:eyJjcmVhdGVkSW5WZXIiOiI0NC44My4yIiwidXBkYXRlZEluVmVyIjoiNDQuODMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicmVub3ZhdGUvY29udGFpbmVyIiwidHlwZS9wYXRjaCJdfQ==-->

Reviewed-on: https://git.hayden.moe/hayden/phoebe/pulls/611
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.

2 participants