Skip to content

Browser will run at 100% if config has no restreams enabled.#22661

Open
brontide wants to merge 1 commit intoblakeblackshear:masterfrom
brontide:master-100-percent-cpu-bug
Open

Browser will run at 100% if config has no restreams enabled.#22661
brontide wants to merge 1 commit intoblakeblackshear:masterfrom
brontide:master-100-percent-cpu-bug

Conversation

@brontide
Copy link
Copy Markdown

The = {} destructuring default in useDeferredStreamMetadata created a new object reference every render while the SWR key was null (during the 2-second defer delay). This triggered an infinite re-render loop through useCameraLiveMode's useEffect dependency on streamMetadata.

Replace with a module-level EMPTY_METADATA constant for referential stability.

Bug introduced in #21072 (97b29d1).

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code
  • Documentation Update

Additional information

AI disclosure

  • No AI tools were used in this PR.
  • AI tools were used in this PR. Details below:

Claude was the debugging agent and wrote the code, we examine a few different code paths but none of them were fruitful. The fix was discovered as a bad data causing an infinite render loop. I reproduced the issue on 0.17.1 and then cherry-picked this fix from my dogfood branch, tested again to confirm the issue was resolved, and then created a PR based on master.

Human reproduced issue, human tested fix, human created PR.

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I can explain every line of code in this PR if asked.
  • UI changes including text have used i18n keys and have been added to the en locale.
  • The code has been formatted using Ruff (ruff format frigate)

Before

Screenshot From 2026-03-26 20-07-16

Settings showing the exact build
Screenshot From 2026-03-26 20-08-48

After with this one patch on master

Screenshot From 2026-03-26 20-13-40

The `= {}` destructuring default in useDeferredStreamMetadata created a
new object reference every render while the SWR key was null (during the
2-second defer delay). This triggered an infinite re-render loop through
useCameraLiveMode's useEffect dependency on streamMetadata.

Replace with a module-level EMPTY_METADATA constant for referential
stability.

Upstream bug introduced in blakeblackshear#21072 (97b29d1).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NickM-27 NickM-27 changed the base branch from master to dev March 27, 2026 01:39
@hawkeye217
Copy link
Copy Markdown
Collaborator

Thanks, you'll have to rebase on dev as we don't have any other changes for master at this time.

Are you using go2rtc restreaming for your cameras? It would seem like the loop would only trigger constant re-rendering when swrKey is null, which would be the case when restreamedStreamNames is empty (i.e., no restreaming) or when the metadata fetch fails. For most users, it seems this would only cause a temporary spike in re-renders while the data is being fetched.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const EMPTY_METADATA: { [key: string]: LiveStreamMetadata } = Object.freeze({});

While it isn't critical here (as we don't mutate it), we do freeze the object like this elsewhere in the codebase.

@brontide
Copy link
Copy Markdown
Author

Apparently you already merged this 3 weeks ago against dev in #22275 but this runaway loop is still present in master.

Please note that this code mirrors what you've already committed 1:1, just bring it back to master so that we don't have the runaway CPU on stable.

@brontide
Copy link
Copy Markdown
Author

Removing the transcoded camera from the config has no effect 100% CPU from endless render bug on image ghcr.io/blakeblackshear/frigate:stable

This should be merged with master.

@hawkeye217
Copy link
Copy Markdown
Collaborator

You might have misunderstood. I would expect this to spin with restreaming disabled for a camera.

As I mentioned, we don't have any other fixes for master at the moment, and I don't think this issue is severe enough to warrant releasing 0.17.2 as it has been in place for a while. If this was a larger issue, I think we would have seen many more reports. We can keep this open and merge if other larger fixes are needed.

@brontide
Copy link
Copy Markdown
Author

All cameras are connected via go2rtc, I don't know why it claims that restreaming is disabled, I can connect via the go2rtc endpoint easily.

@hawkeye217
Copy link
Copy Markdown
Collaborator

All cameras are connected via go2rtc, I don't know why it claims that restreaming is disabled, I can connect via the go2rtc endpoint easily.

That's usually caused by naming mismatches.

@brontide
Copy link
Copy Markdown
Author

Is this page still accurate since this is how it's configured.

https://docs.frigate.video/configuration/restream#reduce-connections-to-camera

@hawkeye217
Copy link
Copy Markdown
Collaborator

Is this page still accurate since this is how it's configured.

https://docs.frigate.video/configuration/restream#reduce-connections-to-camera

Yes

@brontide
Copy link
Copy Markdown
Author

Are you indicating that the go2rtc stream names for main must match the defined camera names? Currently every camera is connected to go2rtc for both detection and recording.

@hawkeye217
Copy link
Copy Markdown
Collaborator

hawkeye217 commented Mar 27, 2026

Are you indicating that the go2rtc stream names for main must match the defined camera names? Currently every camera is connected to go2rtc for both detection and recording.

Either that, or your config should be using the live --> streams directive.

https://docs.frigate.video/configuration/live/#setting-streams-for-live-ui

@brontide
Copy link
Copy Markdown
Author

All cameras now have restream enabled, 100% render loop for 2 seconds every time the / is viewed which is not present after patching.

If restream is required for proper operation it should be flagged as an error in the config.

@hawkeye217
Copy link
Copy Markdown
Collaborator

No, restreaming is not required, but it's recommended to improve live streaming quality and for other apps like Home Assistant:

https://docs.frigate.video/configuration/restream/
https://docs.frigate.video/configuration/live/#live-view-technologies

@brontide
Copy link
Copy Markdown
Author

This will affect all deployments where none of the cameras are setup for restream.

@brontide brontide changed the base branch from dev to master March 27, 2026 14:35
@brontide brontide changed the title Fix 100% browser CPU on live dashboard caused by unstable SWR default Browser will run at 100% if config has no restreams enabled. Mar 27, 2026
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