Repository navigation
fix: memory leak in terminal auto replies - #336022
Megan Rogge (meganrogge) merged 6 commits into
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
| processAutoResponders.delete(match); | ||
| } | ||
| } | ||
| this._autoReplies.clear(); |
There was a problem hiding this comment.
AI Review: The saved _autoReplies map is shared by every window using the same pty host. uninstallAllAutoReplies() carries no owner, and each window's TerminalAutoRepliesContribution runs "uninstall all, then install my own config" when its setting changes. With this clear(), a change in one window now also removes other windows' still-configured replies from the map that handleProcessReady uses for new terminals.
Scenario (traced from source, not reproduced):
- Window A has workspace settings
"terminal.integrated.autoReplies": { "Terminate batch job (Y/N)": "Y\r" }and runs a batch-file task or watch task. - Window B is another trusted workspace, open at the same time, with different workspace-level auto replies.
- Edit only B's workspace
terminal.integrated.autoReplies. Only B's configuration listener fires. It uninstalls globally and reinstalls B's replies only. - In A, a task starts in a new terminal, or you open one and run the script, then interrupt it.
Expected: A's reply still answers Terminate batch job (Y/N)?, as it did in new terminals before this change.
Actual with this PR: the new terminal gets only B's replies and waits at the prompt. Nothing is logged, and A stays this way until its own setting changes or the window reloads. An unattended task in A can hang.
A user-settings change can likely trigger this too. Every window handles it and runs its own uninstall-all/install, and whichever window runs last wins, so A's workspace-only entries can be dropped even though nothing was edited in B.
Before this PR, A's existing terminals already lost their responders in this case. The regression is specific to terminals created afterwards. Removing the clear() would bring the leak back, so that isn't the fix. Possible directions:
- Scope auto replies by owner (for example, a window/client id passed through
ITerminalBackend.installAutoReply/uninstallAllAutoRepliesand the pty host IPC). Then an uninstall only removes that owner's entries and responders. - Or accept the global semantics explicitly and track per-window scoping as a follow-up.
There was a problem hiding this comment.
P2 - still present after the main merge
Rechecked against 03992378c14ce23f0cc2c006a6e3aa89a169c5ff: the merge preserves the repeated-ready disposal fix, but does not address the configuration ownership problem in this thread.
A minimal case needs no concurrent updates: trusted windows A and B have different workspace replies; only B changes its replies to {}; A then opens a new terminal. B clears the shared map and installs nothing. A receives no configuration change, so its still-configured prompt is absent when the new terminal becomes ready. A task waiting for that reply can remain blocked. The per-window configuration listener still performs global uninstall followed by only that window's configuration.
The regression remains specifically new terminals: existing terminals already lost responders before this PR, but new terminals previously reinstalled A's saved entry. Please make replacement/removal preserve other live owners' still-configured replies and add two-owner regression coverage. Removing clear() alone would restore the stale-entry bug.
Both independent reviews confirmed this source path on the current head. This is source-traced, not runtime-reproduced; Code OSS testing was not run.
Dmitriy Vasyura (dmitrivMS)
left a comment
There was a problem hiding this comment.
This seems to be introducing a regression (see other comment)
# Conflicts: # src/vs/platform/terminal/test/node/autoRepliesContribController.test.ts
| } finally { | ||
| contribution.handleProcessDispose(1); | ||
| // Let the response throttle finish before checking disposable ownership. | ||
| await timeout(1100); |
There was a problem hiding this comment.
P3 (non-blocking): use fake timers for both generated test cases
Each case unconditionally waits 1,100 ms here to drain the responder's one-second throttle, adding two real-time waits (about 2.2 seconds total) to every run of this suite.
Please wrap each generated test in runWithFakedTimers({ useFakeTimers: true }, async () => { ... }), matching the immediately following repeated-ready test. The existing await timeout(1100) can remain inside that wrapper so the throttle finishes before disposable checks, but in virtual time rather than slowing the suite down.
Carry a workbench owner ID through local and remote pty calls. Remove only that owner's saved entries and responders, restoring another owner's reply for shared prompts. Clean up the owner's configuration when its contribution is disposed. Add two-owner removal and replacement coverage, shared-prompt fallback and IPC ownership tests. Use fake timers for the auto reply regression tests.
Workbench contributions are disposed after the remote management connection closes. Join owner cleanup during onWillShutdown so it completes before the Last remote disconnect joiner, and stop configuration updates while cleanup is pending. Cover delayed cleanup for initially registered and late backends, repeated owner reloads, preservation of a live peer, and configuration changes during shutdown.
addressed
Megan Rogge (meganrogge)
left a comment
There was a problem hiding this comment.
Thank you!
Details
Removing terminal auto-replies disposes the current responders but leaves the old prompts in the pty host's configuration map. Opening another terminal installs those removed replies again.
Change
Clear the saved auto-replies when uninstalling all replies.
Before
When adding and removing an auto-reply and opening a terminal 37 times, 37 extra responders and their data listeners remain:
After
No more growth in terminal auto-reply responders or their data listeners is detected.
Test Video
video.webm