Repository navigation
fix(main): share one window listener across overlapping requests to stop MaxListeners warnings - #33102
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
No actionable comments were generated in the recent review.
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fdb68287-aff5-40c7-9b30-d65e0aa9c595
Files selected for processing: 25-
src/main/event-listener-fanout.test.tssrc/main/event-listener-fanout.tssrc/main/ipc/filesystem-watcher-local-events.test.tssrc/main/ipc/filesystem-watcher-local-unsubscribe.test.tssrc/main/ipc/filesystem-watcher-test-sender.tssrc/main/ipc/jira/issue-summary-generation.tssrc/main/ipc/native-chat-subscribe-lifecycle.test.tssrc/main/ipc/renderer-lifetime-abort.test.tssrc/main/ipc/renderer-lifetime-abort.tssrc/main/ipc/runtime-environments/runtime-environment-subscription-layout-recording.test.tssrc/main/ipc/runtime-environments/runtime-environments-subscription-lifecycle.test.tssrc/main/ipc/runtime-environments/runtime-environments-subscription-routing.test.tssrc/main/ipc/runtime-environments/runtime-environments-subscription-teardown.test.tssrc/main/ipc/runtime-ssh-access-handlers.tssrc/main/ipc/workspace-cleanup-snapshot-ipc.test.tssrc/main/ipc/workspace-cleanup.tssrc/main/media/media-preview-protocol.test.tssrc/main/media/media-preview-protocol.tssrc/main/window/dropped-path-preparation-ipc.test.tssrc/main/window/project-move-pause.test.tssrc/main/window/project-move-pause.tssrc/main/window/session-tab-close-request-relay.test.tssrc/main/window/session-tab-close-request-relay.tssrc/main/window/terminal-tab-close-request-relay.test.tssrc/main/window/terminal-tab-close-request-relay.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
| export function fireWatcherSenderEvent(sender: SenderEvents, event: string): void { | ||
| const removed = new Set(sender.removeListener.mock.calls.map(([, callback]) => callback)) | ||
| for (const [name, callback] of sender.once.mock.calls) { | ||
| for (const [name, callback] of sender.on.mock.calls) { | ||
| if (name === event && !removed.has(callback)) { | ||
| sender.removeListener(name, callback) |
There was a problem hiding this comment.
Do not remove persistent listeners in the event helper.
SenderEvents.on now represents persistent registration, but fireWatcherSenderEvent calls removeListener before each callback. A cleanup assertion can pass even when the code under test does not release its listener. Repeated events also cannot reach a listener that should remain active. Let the callback or its owner perform removal.
Proposed fix
-
--- "a/src/main/ipc/filesystem-watcher-test-sender.ts" +++ "b/src/main/ipc/filesystem-watcher-test-sender.ts" @@ -20,10 +20,9 @@ /** Fires the live (registered, not removed) `on` handlers for `event`, as Electron would. */ export function fireWatcherSenderEvent(sender: SenderEvents, event: string): void { const removed = new Set(sender.removeListener.mock.calls.map(([, callback]) => callback)) for (const [name, callback] of sender.on.mock.calls) { if (name === event && !removed.has(callback)) { - sender.removeListener(name, callback) callback() } } }
Committable suggestion
-
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.Suggested changesender.removeListener(name, callback)
c5e8b8b to
6edce36
Compare
…equests Per-request lifecycle watchers (renderer-gone aborts, tab-close relays, project-move pause, SSH-access link, Jira summary, workspace-cleanup scans) each added their own destroyed / render-process-gone / did-navigate / closed listener to the long-lived main window. They were removed on settle, but with a dozen remote-runtime subscriptions or tab closes in flight they stacked on top of the window's permanent listeners and tripped MaxListenersExceededWarning. addFanoutListener keeps one native listener per (emitter, event) and fans out to a callback set, detaching when the last subscriber releases.
bc47047 to
31e9eb0
Compare
ELI5
The main Orca window is like a shared bulletin board. Lots of short jobs (a file watch, a tab close, a remote-server subscription) pin a note on it saying "tell me if this window goes away". Each job did take its note down when it finished, but when many jobs ran at the same time the board filled up past its 10-note safety limit and Orca logged a "possible memory leak" warning. Now all those jobs share one note, and that note lists everyone who wants to know.
What Changed
Before: on a busy session (WSL host connected, renderer reloads, projects being moved) the main-process log filled with
MaxListenersExceededWarning: ... 11 destroyed / render-process-gone / did-navigate listeners added to [WebContents]and11 closed listeners added to [BrowserWindow]. Each in-flight request had added its own listener to the main window. The window already carries 7–9 permanent listeners per event from startup, so two or three overlapping requests were enough to cross the limit. Every reload or crash also walked one listener per open request.After: short-lived watchers subscribe through a new
addFanoutListener(src/main/event-listener-fanout.ts). It attaches one listener per window-and-event, keeps the interested callbacks in a set, and removes that listener when the last subscriber leaves. However many requests overlap, each window event costs one extra listener.Callers moved onto it:
abortWhenRendererGone(src/main/ipc/renderer-lifetime-abort.ts): used by remote-runtime subscriptions, filesystem watchers, file mutations and downloads, native chat, emulator streams, log tail, media preview and dropped-path copies. This was the main source of thedestroyed,render-process-goneanddid-navigatewarnings.src/main/window/*-tab-close-request-relay.ts). Session closes can stay pending for up to 5 minutes, so these keptclosed,destroyedandrender-process-gonelisteners on the window. TheiripcMainreply listeners now share one listener too.src/main/window/project-move-pause.ts), plus the per-requestdestroyedwatchers in SSH-access link, Jira summary generation and workspace-cleanup scans.There is no user-visible behaviour change. Requests are still cancelled on exactly the same events.
Why
setMaxListenerswould only hide the warning. Listeners would still grow with the number of in-flight requests.Linked Issue
Internal: found in Windows main-process logs from a WSL hosts build.
Visual Proof
N/A: main-process listener bookkeeping only. Nothing on screen changes.
Testing
New
src/main/event-listener-fanout.test.ts: 25 overlapping subscribers share one listener, the count returns to zero after release, release during dispatch works, double release is safe, and the listener is re-attached after it drains.New overlap tests on
abortWhenRendererGone, both tab-close relays and project-move pause. Each starts 12–25 concurrent requests, checks there is exactly one listener per event (window, WebContents andipcMain), then settles them all and checks the emitters return to zero listeners. Before this change those relay tests themselves printedMaxListenersExceededWarning.Test doubles that only implemented
oncenow implementon.pnpm tc, oxlint on changed files andpnpm run check:code-quality:changedpass. All ofsrc/main/ipc,src/main/windowandsrc/main/mediapass (639 files).Platforms: macOS unit tests only. The warning was seen on Windows, but the code path has no platform branches.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
No wire or protocol changes, so mixed client/host versions are unaffected. SSH and WSL remote-runtime subscriptions benefit directly, because each one used to hold its own listeners. Cancellation semantics are unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)