Skip to content

fix: make sure register handler when ipc emitter add listener - #323663

Merged
roblourens merged 1 commit into
microsoft:mainfrom
theanarkh:optimize_ipc
Jul 7, 2026
Merged

fix: make sure register handler when ipc emitter add listener#323663
roblourens merged 1 commit into
microsoft:mainfrom
theanarkh:optimize_ipc

Conversation

@theanarkh

@theanarkh theanarkh (theanarkh) commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes: #324678

When the last listener is disposed, we will remove the handler from the map. However, we will not add the handler back to the map when re-subscribing to the emitter, so the event will not be emitted anymore. It is better register handler in onWillAddFirstListener and delete it in onDidRemoveLastListener.

example.

const emitter = client.listen('hello');
const dispose1 = emitter(() => {);
dispose1.dispose();
// can not receive any messages.
const dispose2 = emitter(() => {);

Copilot AI review requested due to automatic review settings June 30, 2026 05:02

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 ChannelClient.requestEvent() in src/vs/base/parts/ipc/common/ipc.ts so that re-adding a listener to an IPC event after disposing the previous listener will correctly receive messages again.

Changes:

  • Register the IPC response handler in Emitter’s onWillAddFirstListener hook (instead of at event creation time).
  • Ensure the handler is re-registered whenever the event transitions from 0 → 1 listeners, matching the existing cleanup on last-listener removal.

@roblourens roblourens 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.

Thanks for the PR, I think this change is good but please file an issue with a better description of the issue, and add unit tests for the scenario

     When the last listener is disposed, we will remove the handler from the map.
     However, we will not add the handler back to the map when re-subscribing to the emitter,
     so the event will not be emitted anymore. It is better register handler in onWillAddFirstListener and
     delete it in onDidRemoveLastListener.
@theanarkh

Copy link
Copy Markdown
Contributor Author

roblourens Thanks ! I have updated the code, please help review again.

@roblourens

roblourens commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thanks, can you open an issue?

@theanarkh

Copy link
Copy Markdown
Contributor Author

Thanks, can you open an issue?

Done.

@roblourens
roblourens enabled auto-merge (squash) July 7, 2026 14:45
@roblourens
roblourens merged commit b08e380 into microsoft:main Jul 7, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.129.0 milestone Jul 7, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue about ChannelClient.requestEvent

6 participants