Skip to content

fix(gui-client): remove bad hook dependencies#9537

Merged
thomaseizinger merged 2 commits into
mainfrom
fix/gui-client-high-cpu
Jun 15, 2025
Merged

fix(gui-client): remove bad hook dependencies#9537
thomaseizinger merged 2 commits into
mainfrom
fix/gui-client-high-cpu

Conversation

@thomaseizinger

@thomaseizinger thomaseizinger commented Jun 15, 2025

Copy link
Copy Markdown
Member

The removed hook dependencies are invalid because the side-effect specified in useEffect does in fact not depend on them. However, as a result of these dependencies, the useEffect closure appears to run in an end-less loop, constantly sending the update_state command to the backend which in turn re-sends all state to the frontend, causing a massive CPU and memory spike.

Resolves: #9519

@vercel

vercel Bot commented Jun 15, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2025 4:49pm

Copilot AI 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.

Pull Request Overview

This PR fixes a performance issue in the GUI client by removing unnecessary hook dependencies that led to an endless update loop causing CPU and memory spikes.

  • Removed 'location' and 'handleClick' from the useEffect dependency array.
  • Prevents repeated sending of the update_state command to the backend.

logsRecountedUnlisten.then((unlistenFn) => unlistenFn());
};
}, [location, handleClick]);
}, []);

Copilot AI Jun 15, 2025

Copy link

Choose a reason for hiding this comment

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

Ensure that none of the values 'location' or 'handleClick' are referenced within the effect body after removing them from the dependency array to avoid stale closures.

Copilot uses AI. Check for mistakes.
@thomaseizinger
thomaseizinger enabled auto-merge June 15, 2025 16:46

@jamilbk jamilbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤦‍♂️

@jamilbk jamilbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a bit worrying this only popped up when wired up to the Rust proc. I think the lesson learned here is that making GUI changes requires the developer to be able to spin up the full GUI client, not just run the UI with pnpm vite dev as it risks these types of side effect issues.

@thomaseizinger

thomaseizinger commented Jun 15, 2025

Copy link
Copy Markdown
Member Author

It's a bit worrying this only popped up when wired up to the Rust proc. I think the lesson learned here is that making GUI changes requires the developer to be able to spin up the full GUI client, not just run the UI with pnpm vite dev as it risks these types of side effect issues.

We also need more static analysis. I believe eslint would have caught this with the React plugin. Not resulting issue but the violation of the Rules of Hooks.

@thomaseizinger
thomaseizinger added this pull request to the merge queue Jun 15, 2025
Merged via the queue into main with commit 3660f53 Jun 15, 2025
219 of 221 checks passed
@thomaseizinger
thomaseizinger deleted the fix/gui-client-high-cpu branch June 15, 2025 17:23
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.

memory leak / high cpu usage in rust gui

3 participants