Skip to content

ipc: Avoid buffering unused native host blur events - #328535

Merged
roblourens merged 2 commits into
microsoft:mainfrom
roblourens:roblou/fix-native-host-blur-buffer
Aug 2, 2026
Merged

roblourens merged 2 commits into
microsoft:mainfrom
roblourens:roblou/fix-native-host-blur-buffer

Conversation

@roblourens

Copy link
Copy Markdown
Member

Problem

ProxyChannel.fromService eagerly subscribes to and buffers service events so startup events can be replayed when an IPC client attaches. onDidBlurMainWindow has no IPC consumer, so every main-window blur was retained indefinitely and the eager proxy subscription was unnecessary.

In dev builds this produces an [Event.buffer][onDidBlurMainWindow] potential LEAK detected warning after buffered events remain unconsumed.

History

This is long-standing rather than a recent regression:

  • 42f5594892 (2023-11-02) split focus/blur into main-only and main-or-auxiliary events. Renderer consumers moved to the combined event, leaving the main-only blur buffer without an IPC listener.
  • a837f16fbe (2026-02-28) added Event.buffer leak diagnostics, making the existing unbounded buffer visible.

The main-only focus event remains buffered because Settings Sync consumes it through the shared-process native host channel.

Fix

  • add an opt-in unbufferedEvents proxy-channel option that subscribes only when an IPC client listens
  • make onDidBlurMainWindow lazy/unbuffered while preserving the event API for future consumers
  • cover lazy subscription, lack of replay, and listener cleanup with an IPC unit test

CC Benjamin Pasero (@bpasero) for the auxiliary-window event history.

Validation

  • npm run compile
  • ./scripts/test.sh --run src/vs/base/parts/ipc/test/common/ipc.test.ts (23 passing)
  • npm run precommit

(Written by Copilot)

Allow selected proxy events to subscribe lazily, and apply that behavior to the main-window blur event that has no IPC consumer. This avoids an unbounded event buffer while preserving the event for future listeners.

(Written by Copilot)

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings August 1, 2026 00:33

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

Adds opt-in lazy event subscriptions to prevent unused IPC events from buffering indefinitely.

Changes:

  • Introduces unbufferedEvents for ProxyChannel.fromService.
  • Makes onDidBlurMainWindow lazy and non-replaying.
  • Tests lazy subscription, delivery, and cleanup.
Show a summary per file
File Description
src/vs/base/parts/ipc/common/ipc.ts Implements unbuffered proxy events.
src/vs/base/parts/ipc/test/common/ipc.test.ts Tests subscription lifecycle.
src/vs/code/electron-main/app.ts Configures main-window blur as unbuffered.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

Document why the main-window blur event must not use the proxy event buffer.\n\n(Written by Copilot)\n\nCo-authored-by: Copilot <[email protected]>
@roblourens
roblourens marked this pull request as ready for review August 2, 2026 00:07
@roblourens
roblourens enabled auto-merge (squash) August 2, 2026 00:07
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Robo (@deepak1556)

Matched files:

  • src/vs/code/electron-main/app.ts

@roblourens
roblourens merged commit 876ce72 into microsoft:main Aug 2, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Aug 2, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants