Skip to content

Fix receiver load balance threshold initialization - #4678

Merged
boks1971 merged 1 commit into
livekit:masterfrom
FrankMartining:fix/receiver-load-balance-threshold
Jul 16, 2026
Merged

Fix receiver load balance threshold initialization#4678
boks1971 merged 1 commit into
livekit:masterfrom
FrankMartining:fix/receiver-load-balance-threshold

Conversation

@FrankMartining

Copy link
Copy Markdown
Contributor

Problem

NewReceiverBase creates the DownTrackSpreader before receiver options
are applied.

The spreader is therefore initialized with the default lbThreshold of
zero. WithLoadBalanceThreshold(20) is applied afterward, but
SetLBThreshold previously updated only the ReceiverBase field and not
the already-created spreader.

A zero spreader threshold is treated as 1,000,000, effectively disabling
parallel DownTrack writes for large rooms. This can cause forwarding
latency and packet queue buildup with large subscriber counts, especially
for single-layer screen share tracks.

Fix

  • Propagate SetLBThreshold updates to the active DownTrackSpreader.
  • Protect threshold reads and writes with the spreader mutex.
  • Add a regression test for updating the threshold.

Testing

  • go test ./pkg/sfu ./pkg/sfu/utils ./pkg/rtc -count=1
  • go test -race ./pkg/sfu ./pkg/sfu/utils -count=1

@FrankMartining
FrankMartining requested a review from a team as a code owner July 16, 2026 10:40
@CLAassistant

CLAassistant commented Jul 16, 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

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 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 so much for catching this. Great catch!

Just some small comments,

  • I think the test file can be removed. It is simple enough.
  • Can you please add it to redreceiver.go and redprimaryreceiver.go also? I can take care of it if you would rather leave this at this point. Basically, do something like
    1. Add method to REDTransformer interface in receiver_base.go
    2. In SetLBThreshold, do loadREDTransformer and if not nil, call the method added to REDTransformer interface.
    3. Implement the method in those two RED files and pass it on to the spreader they have.

@@ -0,0 +1,42 @@
// Copyright 2026 LiveKit, Inc.

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.

this test can be removed. It is simple enough.

@boks1971

Copy link
Copy Markdown
Contributor

I will merge this now and do the changes I suggested. Thank you once again for catching this.

@boks1971
boks1971 merged commit 15a9542 into livekit:master Jul 16, 2026
3 of 6 checks passed
boks1971 added a commit that referenced this pull request Jul 16, 2026
Following up on this PR (#4678 -
great catch btw, thank you), propagating the spreader threshold to RED
receivers also.

Removing the test as it was a simple case and that would not have caught
the original issue.
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request Jul 18, 2026
…3 ➔ v1.13.4) (#1641)

This PR contains the following updates:

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

---

### Release Notes

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

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

[Compare Source](livekit/livekit@v1.13.3...v1.13.4)

##### Added

- added mocking function for SIP dialing methods ([#&#8203;4642](livekit/livekit#4642))
- Add signal tests to test-server ([#&#8203;4653](livekit/livekit#4653))
- Add option to exclude local IPv6 candidates. ([#&#8203;4657](livekit/livekit#4657))
- Add a method to get forward stats via API method. ([#&#8203;4664](livekit/livekit#4664))
- Add drop-on-close signal test scenario ([#&#8203;4669](livekit/livekit#4669))
- Log soft validation errors. ([#&#8203;4671](livekit/livekit#4671))
- add redaction flag in Job ([#&#8203;4650](livekit/livekit#4650))

##### Changed

- simpler mock protocol ([#&#8203;4641](livekit/livekit#4641))
- Make IsConnectionCanceled available at LocalParticipant interface. ([#&#8203;4643](livekit/livekit#4643))
- Update actions/checkout action to v7 ([#&#8203;4646](livekit/livekit#4646))
- Update protocol. ([#&#8203;4648](livekit/livekit#4648))
- Export migration to LocalParticipant interface. ([#&#8203;4652](livekit/livekit#4652))
- Record final RTC state as success/failure. ([#&#8203;4658](livekit/livekit#4658))
- Omit rtx/out-of-order packets from forwarding delay measurement. ([#&#8203;4659](livekit/livekit#4659))
- Move ForwardStats aggregation off the packet forwarding path ([#&#8203;4660](livekit/livekit#4660))
- protocol deps to get parallel exec alloc reduction ([#&#8203;4662](livekit/livekit#4662))
- Update pion/ice to deal with hang on close. ([#&#8203;4672](livekit/livekit#4672))
- Add more details to unreliable data channel drop error. ([#&#8203;4673](livekit/livekit#4673))
- Record `rtc_success` prom as soon as RTC connects. ([#&#8203;4677](livekit/livekit#4677))
- Use proto logger to get named enums in the logs. ([#&#8203;4679](livekit/livekit#4679))
- Propagate spreader threshold to RED receivers. ([#&#8203;4683](livekit/livekit#4683))
- Prefer QDisc.Stats till go-tc addresses QDisc.Stats2 parsing ([#&#8203;4685](livekit/livekit#4685))
- Bump protocol version to fix call to Validate. ([#&#8203;4686](livekit/livekit#4686))

##### Fixed

- bound data-track buffering under downlink congestion (targetLatency) ([#&#8203;4667](livekit/livekit#4667))
- Guard against nil TC qdisc stats to prevent SIGSEGV ([#&#8203;4668](livekit/livekit#4668))
- Fix goroutine leak from orphaned signal relay streams ([#&#8203;4674](livekit/livekit#4674))
- don't undercount data channel bitrate over idle gaps ([#&#8203;4676](livekit/livekit#4676))
- Fix receiver load balance threshold initialization ([#&#8203;4678](livekit/livekit#4678))
- rtc: guard against nil subscriber in TransportManager.HandleAnswer ([#&#8203;4680](livekit/livekit#4680))
- Potential fix for code scanning alert no. 42: Incorrect conversion between integer types ([#&#8203;4684](livekit/livekit#4684))

</details>

---

### Configuration

📅 **Schedule**: 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 [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/1641
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.

3 participants