Skip to content

fix(suite-desktop): clean up accumulated Electron listeners on re-init#28241

Draft
mroz22 wants to merge 2 commits into
developfrom
mroz22/desktop-listener-cleanup
Draft

fix(suite-desktop): clean up accumulated Electron listeners on re-init#28241
mroz22 wants to merge 2 commits into
developfrom
mroz22/desktop-listener-cleanup

Conversation

@mroz22
Copy link
Copy Markdown
Contributor

@mroz22 mroz22 commented Jun 1, 2026

Summary

Two isolated Electron listener-cleanup fixes, split out of the broader audit in #27978 so they can be reviewed independently of the transport/connect changes. Both are single-concern and touch only desktop packages.

Fixes

  • @trezor/suite-desktop-corepower-monitor
    Listeners (lock-screen/unlock-screen/suspend/resume) were registered inside mainWindowProxy.on('init', …), which fires again on every reactivateWindow() after the window is destroyed — so each window recreation stacked another full set of powerMonitor listeners on the global Electron singleton. Moved registration out of the init callback (runs once per module init) and switched the suspend handler to mainWindowProxy.getInstance()?.webContents.send(...) so it always targets the current window.

  • @trezor/suite-desktop-uiDesktopUpdater / Protocol
    DesktopUpdater.tsx registered 8 desktopApi update-channel listeners but only cleaned up the interval; toggling desktopUpdate.enabled re-ran the effect and leaked the previous listeners. Now the effect removes all update listeners on cleanup. Protocol.tsx adds the missing removeAllListeners('protocol/open') cleanup.

Why split out

These are in packages no other PR in the leak-audit stream touches, each is a self-contained "add the missing cleanup" change, and each is independently revertible — so they don't need to wait on the transport/connect review.

Related PRs (listener-leak audit stream)

Test plan

  • lint:js clean on all three changed files
  • CI type-check + unit (full monorepo build)

🤖 Generated with Claude Code

🤖 LLM Test Recommendations

Summary: The three changed files have very limited E2E test relevance. power-monitor.ts (desktop power monitoring) and DesktopUpdater.tsx (desktop auto-updater UI) are desktop-core/desktop-UI modules with no static test coverage and no E2E tests that exercise power monitoring or update flows. Protocol.tsx is a broadly imported support component (URI/deep-link protocol handler) that maps to 121 tests — but none of the 142 analyzed tests specifically exercise protocol/deep-link handling behavior, meaning the static mapping is purely transitive. Since no test directly exercises the changed functionality (power monitor behavior, desktop updater UI, or protocol URI handling), no E2E tests are recommended. The risk is low for user-facing regressions detectable by these E2E tests; manual or unit-level testing of these modules would be more appropriate.

Changed files (3)
  • packages/suite-desktop-core/src/modules/power-monitor.ts
  • packages/suite-desktop-ui/src/support/DesktopUpdater.tsx
  • packages/suite/src/support/suite/Protocol.tsx

No test recommendations found.

⚠️ Changes with no test coverage (3)

  • packages/suite-desktop-core/src/modules/power-monitor.ts
  • packages/suite-desktop-ui/src/support/DesktopUpdater.tsx
  • packages/suite/src/support/suite/Protocol.tsx

Updated: 2026-06-01T15:02:08.157Z

🔍 Currents Test Results

🔍 Suite desktop test results: View in Currents

🔍 Suite web test results: View in Currents

🔒 Quarantined E2E Tests

Trezor Suite (web) — 10 test(s)
Test Type
Account metadata > dropbox provider 🤖 auto
Export transactions > Go to account and try to export all possible variants (pdf, csv, json) 🤖 auto
Passphrase with cardano > verify cardano address behind passphrase 🤖 auto
Cardano > Basic cardano walkthrough 🤖 auto
Public Keys > Check ada XPUB 🤖 auto
Account types suite > Add-account-types-non-BTC-coins 🤖 auto
Quarantine test: "Onboarding - create wallet,Success (basic)" 🙋 manual
Quarantine test: "Database migration,Db migration between: release/22.5/web => develop/web" 🙋 manual
Quarantine test: "Multiple sessions,Session overtaken by another" 🙋 manual
Quarantine test: "Recovery T2T1 - dry run,Recovery after partial recovery" 🙋 manual

Updated: 2026-06-01T15:08:40.352Z • 10 test(s) total

Trezor Suite (desktop) — 6 test(s)
Test Type
Passphrase with cardano > verify cardano address behind passphrase 🤖 auto
Cardano > Basic cardano walkthrough 🤖 auto
Public Keys > Check ada XPUB 🤖 auto
Account types suite > Add-account-types-non-BTC-coins 🤖 auto
Onboarding - create wallet > Success (basic) 🤖 auto
Quarantine test: "Multiple sessions,Session overtaken by another" 🙋 manual

Updated: 2026-06-01T15:05:23.654Z • 6 test(s) total

🌐 Preview deployments

🌐 Suite Web preview: https://dev.suite.sldev.cz/suite-web/mroz22/desktop-listener-cleanup/web/

mroz22 added 2 commits June 1, 2026 16:48
Stop accumulation of `powerMonitor` listeners in
`suite-desktop-core/modules/power-monitor.ts`. Document findings from
the desktop and connect packages audit.
Fix two IPC listener leaks: DesktopUpdater.tsx leaked 8 update channels
without cleanup when `desktopUpdate.enabled` changed, and Protocol.tsx
was missing cleanup for `protocol/open`. Document new false positives
from the suite/suite-desktop-ui audit.
@mroz22 mroz22 added code Code improvements no-project This label is used to specify that PR doesn't need to be added to a project labels Jun 1, 2026
@mroz22 mroz22 requested a review from Copilot June 1, 2026 15:12
Copy link
Copy Markdown

Copilot AI left a comment

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 Electron IPC/listener leaks in the desktop app by ensuring listeners are not accumulated when parts of the app are re-initialized (e.g., window recreation or settings toggles), preventing duplicated event handling and potential memory growth.

Changes:

  • Register powerMonitor listeners only once (module init), and ensure suspend targets the current window instance.
  • Add missing desktopApi listener cleanup in DesktopUpdater when the effect re-runs/unmounts.
  • Add missing protocol/open listener cleanup in Protocol.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/suite-desktop-core/src/modules/power-monitor.ts Moves powerMonitor listener registration out of window init to avoid stacking across window recreation; targets current window on suspend.
packages/suite-desktop-ui/src/support/DesktopUpdater.tsx Ensures all updater-related desktopApi listeners are removed in effect cleanup to prevent leaks when desktopUpdate.enabled toggles.
packages/suite/src/support/suite/Protocol.tsx Adds cleanup to remove protocol/open listeners on unmount/re-run to prevent listener accumulation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Code improvements no-project This label is used to specify that PR doesn't need to be added to a project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants