Repository navigation
fix pty output make main process oom - #285419
theanarkh (theanarkh) wants to merge 2 commits into
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Robo (@deepak1556)Matched files:
|
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory leak (OOM) in the main Electron process caused by unbounded buffering of PTY process output. The local PTY process communicates directly with the renderer process via MessagePort, but the main process was also buffering all onProcessData events even though they were never consumed, leading to memory exhaustion.
Key Changes:
- Added a
skipoption toProxyChannel.fromServiceto selectively exclude events from registration - Applied the skip option to exclude
onProcessDataevents from the main process PTY service channel
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/vs/base/parts/ipc/common/ipc.ts |
Added skip option to ICreateServiceChannelOptions interface to allow selective event registration filtering |
src/vs/code/electron-main/app.ts |
Applied skip option to exclude onProcessData from the PTY host channel registration in main process |
bd57057 to
e2bb946
Compare
e2bb946 to
4eaa235
Compare
Daniel Imms (Tyriar)
left a comment
There was a problem hiding this comment.
lgtm thanks!
FYI João Moreno (@joaomoreno) Alexandru Dima (@alexdima) if you have thoughts on ipc/ parts
| * If return true for a event key, we add the handler to event | ||
| * until the first listener is registered. | ||
| */ | ||
| isLazyEvent?: (key: string) => boolean; |
There was a problem hiding this comment.
I am reading this comment and fail to understand what actually happens when I use this option. If I understand correctly, a "lazy" event will not buffer any data until a first listener is added. But then I would update this comment to actually explain this better. And should be called differently?
There was a problem hiding this comment.
Yes. I have updated the comment, please help review again .
| // Terminal | ||
| const ptyHostChannel = ProxyChannel.fromService(accessor.get(ILocalPtyService), disposables); | ||
| const ptyHostChannel = ProxyChannel.fromService(accessor.get(ILocalPtyService), disposables, { | ||
| isLazyEvent: (key: string) => key === 'onProcessData' |
There was a problem hiding this comment.
Whats the rule here to decide if an event should be lazy? Does this apply to other proxy channels?
There was a problem hiding this comment.
Thanks for reviewing ! An event should be lazy if it is triggered automatically but may not have subscribers; otherwise, the event data will be cached in the buffer (Event.buffer), causing a memory leak. I only find that ptyHostService.onProcessData should be lazy currently.
There was a problem hiding this comment.
theanarkh (@theanarkh) I think what Benjamin Pasero (@bpasero) is likely getting at is this should get fixed generically to prevent future leaks like this in the future. onProcessData is used, but conditionally, just because an event isn't listened to shouldn't mean the data should hang around forever. Any thoughts on how we could solve this generically for all events without hardcoding this particular event or compromising performance?
There was a problem hiding this comment.
onProcessData is used in both local and remote scenarios. Only in the local scenario it have no subscribers. Therefore, we cannot directly configure onProcessData event to skip event buffer. Instead, we configure it in the caller of fromService. I haven't thought of a general way to deal with this problem currently.
Head branch was pushed to by a user without write access
4eaa235 to
3415bc2
Compare
There was a problem hiding this comment.
I'm also not a big fan of introducing a lazy concept. A few alternatives:
- Since the proxy stuff is all just-works-magic, why not having a decorator on the method like
@IPCNoBufferor something, instead of string based matching? - Avoid the magic proxy and use manually crafted channels (example) for the ptyhost, the old fashioned way.
|
João Moreno (@joaomoreno) I've prepared #298468 which should point us to the other leaking places (3-4 right now). The question I have is ... why the usage of I also think this way of using |
|
Superseded by #328535 |
Fixes #234393
The local pty process communicates directly with the render process, but the main process save the output of pty process to buffer and there is no consumer.
Running
in the terminal and take a JS heap snapshot of main process.
take JS heap snapshot again after some time.