gemini-cli - 💡(How to fix) Fix Too many open files in system error (126) and forkpty(3) failure during high-volume shell command execution. [1 comments, 2 participants]

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…
GitHub stats
google-gemini/gemini-cli#26384Fetched 2026-05-03 04:52:16
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Timeline (top)
commented ×1labeled ×1

Error Message

in a large workspace, the CLI returned a Too many open files in system error (Exit Code: 126). Following The error occurred during a session involving deep codebase research and batch updates to 11 different

RAW_BUFFERClick to expand / collapse

What happened?

While executing a series of shell commands and sub-agent tasks to configure multiple profile directories in a large workspace, the CLI returned a Too many open files in system error (Exit Code: 126). Following this, subsequent attempts to execute any shell commands failed with forkpty(3) failed, indicating the process limit or file descriptor limit for the session had been reached, making it impossible to continue working without a restart.

[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.

What did you expect to happen?

The CLI should handle high volumes of tool calls and file operations without exhausting system file descriptors, or it should provide a graceful way to recover/clear the descriptor pool without crashing the tool execution layer.

Client information

  • CLI Version: 0.40.1
  • Git Commit: 7a382e066
  • Session ID: 3fe14e40-963e-43dc-8f89-cb304abbb5fe
  • Operating System: linux v24.14.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: oauth-personal
  • Memory Usage: 567.7 MB
  • Terminal Name: Unknown
  • Terminal Background: #1e1e1e
  • Kitty Keyboard Protocol: Unsupported
  • IDE Client: Antigravity

Login information

Logged in via Google Account (oauth-personal)

Anything else we need to know?

The error occurred during a session involving deep codebase research and batch updates to 11 different configuration directories. The workspace contains thousands of files across various service and library directories. The failure happened after several parallel invoke_agent and run_shell_command calls.

extent analysis

TL;DR

Increase the system's file descriptor limit to prevent the "Too many open files" error.

Guidance

  • Identify the current file descriptor limit using ulimit -n and consider increasing it to a higher value, such as 1024 or 2048, depending on the system's capabilities.
  • Verify that the CLI is properly closing file descriptors after each task completion to prevent descriptor leaks.
  • Consider implementing a retry mechanism with a delay between attempts to execute shell commands, allowing the system to recover from temporary file descriptor exhaustion.
  • Review the codebase research and batch update process to optimize file operations and minimize the number of concurrent file descriptor openings.

Example

No specific code snippet can be provided without more context, but ensuring proper file descriptor closure can be achieved by using close() or fclose() functions after file operations.

Notes

The solution may vary depending on the specific system configuration and the CLI's implementation. Increasing the file descriptor limit may have system-wide implications and should be done with caution.

Recommendation

Apply a workaround by increasing the file descriptor limit, as upgrading to a fixed version is not mentioned in the issue. This is a temporary solution to alleviate the immediate problem, but a more permanent fix may require modifications to the CLI or the codebase research and batch update process.

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 Too many open files in system error (126) and forkpty(3) failure during high-volume shell command execution. [1 comments, 2 participants]