Repository navigation
fix: memory leak in terminal process startup - #340582
Dmitriy Vasyura (dmitrivMS) merged 6 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The Windows-only spawn-throttling disposal path lacks deterministic test coverage.
1 open finding
What changed in this PR
Prevents PTY and title-timer creation after terminal disposal during asynchronous startup.
Changes:
- Adds a post-throttle disposal guard.
- Adds startup disposal and launch validation tests.
| File | Description |
|---|---|
terminalProcess.ts |
Stops startup after disposal. |
terminalProcess.test.ts |
Tests startup and disposal behavior. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Windows shutdown-during-validation test can fail before disposalAt the current head, However, immediate shutdown is explicitly restricted to non-Windows. On Windows, shutdown instead schedules the 250-ms data-flush timer. In an isolated run, the first spawn-throttle call has no previous spawn/kill operation to wait for. If validation completes before that shutdown timer, the terminal is still undisposed at the new guard, so startup reaches the pre-spawn trace and increments The fixture counts that trace; it does not stub native PTY creation, so this path can also launch a real child. This is a substantive test regression from enabling the suite on Windows, not evidence that the production disposal guard is incorrect. Please make this test deterministic by holding startup until shutdown/disposal has completed before releasing it. Alternatively, keep this immediate-shutdown-dependent test skipped on Windows while retaining the new deterministic throttle-disposal test there. Validation: source-traced at the pinned head; I have not executed this test on Windows. |
Dmitriy Vasyura (dmitrivMS)
left a comment
There was a problem hiding this comment.
Please consider the comment.


Details
A terminal can be shut down while executable validation or spawn throttling is still pending. Startup then creates a PTY and title-polling timer after disposal, so that timer is never cleared.
Change
Check whether the terminal has been disposed after the final await and return before spawning the PTY.
Before
When disposing terminals during startup 37 times, disposed terminal instances and title-polling callbacks grow by 37:
After
No more leak detected.
Test Video
test-video.webm
AI disclosure: Model: GPT-6.1-Sol. Worktime: 26 min