gemini-cli - 💡(How to fix) Fix PTY memory and file descriptor leak in ShellExecutionService [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

This issue is the root cause for ENXIO errors in long-lived CLI sessions where PTY exhaustion occurs because the underlying FDs are never released from the tracking maps. PR has already been opened.

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

What happened?

There is a critical memory and file descriptor leak in ShellExecutionService. When long-running background shell executions (like MCP servers) are started, their ptyProcess and headlessTerminal instances are never garbage collected if the log stream fails to emit an end() callback.

Specifically, activePtys.delete(ptyPid) is currently wrapped inside a Promise .then() of cleanupLogStream(ptyPid). If the background log stream has already been destroyed or fails to trigger its end() callback, the Promise hangs indefinitely. This leaves the PTY process and its massive scrollback buffer in memory permanently.

Furthermore, the onData and onExit event listeners returned by node-pty were not being properly disposed, causing potential closure leaks.

What did you expect to happen?

I expect activePtys entries and headlessTerminal scrollback buffers to be unconditionally cleaned up and garbage collected as soon as a PTY process exits or is killed, regardless of whether the log stream flushes successfully or hangs.

Client information

<details> <summary>Client Information</summary>

OS: macOS Version: 0.44.0-nightly

</details>

Login information

N/A - Core shell execution engine.

Anything else we need to know?

This issue is the root cause for ENXIO errors in long-lived CLI sessions where PTY exhaustion occurs because the underlying FDs are never released from the tracking maps. PR has already been opened.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix PTY memory and file descriptor leak in ShellExecutionService [1 pull requests]