gemini-cli - 💡(How to fix) Fix Gemini CLI crashes with `ioctl(2) failed, EBADF` in `node-pty` during `resizePty`

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…

Gemini CLI crashes with a critical error when running in an SSH terminal on a Linux hosting environment.

The crash happens inside @lydell/node-pty, during a PTY resize operation:

ERROR ioctl(2) failed, EBADF

The error appears to come from UnixTerminal.resize() when calling:

pty.resize(this._fd, cols, rows);

Error Message

An unexpected critical error occurred: Error: ioctl(2) failed, EBADF

Root Cause

Gemini CLI crashes with a critical error when running in an SSH terminal on a Linux hosting environment.

The crash happens inside @lydell/node-pty, during a PTY resize operation:

ERROR ioctl(2) failed, EBADF

The error appears to come from UnixTerminal.resize() when calling:

pty.resize(this._fd, cols, rows);

Code Example

ERROR ioctl(2) failed, EBADF

---

pty.resize(this._fd, cols, rows);

---

OS: Linux
Shell: bash
Node version: v24.13.0
npm version: 11.6.2
Gemini CLI version: 0.44.0
Install method: npm global install via nvm
Node manager: nvm
Terminal context: SSH session on a managed hosting server

---

~/.nvm/versions/node/v24.13.0/bin/node
~/.nvm/versions/node/v24.13.0/bin/npm
~/.nvm/versions/node/v24.13.0/bin/gemini

---

which node
which npm
which gemini
node -v
npm -v
gemini --version

---

~/.nvm/versions/node/v24.13.0/bin/node
~/.nvm/versions/node/v24.13.0/bin/npm
~/.nvm/versions/node/v24.13.0/bin/gemini
v24.13.0
11.6.2
0.44.0

---

ERROR ioctl(2) failed, EBADF

~/.nvm/versions/node/v24.13.0/lib/node_modules/@google/gemini-cli/node_modules/@lydell/node-pty/unixTerminal.js:243:13

240: if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
241:     throw new Error('resizing must be done using positive cols and rows');
242: }
243: pty.resize(this._fd, cols, rows);
244: this._cols = cols;
245: this._rows = rows;
246: };

- UnixTerminal.resize (.../@google/gemini-cli/node_modules/@lydell/node-pty/unixTerminal.js:243:13)
- _ShellExecutionService.resizePty (.../@google/gemini-cli/bundle/chunk-BE42OOYM.js:320262:30)
- (.../@google/gemini-cli/bundle/interactiveCli-RDMZS6KL.js:6529:31)
- commitHookEffectListMount (.../@google/gemini-cli/bundle/chunk-VUERI7WB.js:5260:30)
- commitPassiveMountOnFiber (.../@google/gemini-cli/bundle/chunk-VUERI7WB.js:6282:29)
- recursivelyTraversePassiveMountEffects (.../@google/gemini-cli/bundle/chunk-VUERI7WB.js:6263:13)

---

An unexpected critical error occurred: Error: ioctl(2) failed, EBADF
RAW_BUFFERClick to expand / collapse

What happened?

Gemini CLI crashes with ioctl(2) failed, EBADF in node-pty during resizePty

Description

Gemini CLI crashes with a critical error when running in an SSH terminal on a Linux hosting environment.

The crash happens inside @lydell/node-pty, during a PTY resize operation:

ERROR ioctl(2) failed, EBADF

The error appears to come from UnixTerminal.resize() when calling:

pty.resize(this._fd, cols, rows);

Environment

OS: Linux
Shell: bash
Node version: v24.13.0
npm version: 11.6.2
Gemini CLI version: 0.44.0
Install method: npm global install via nvm
Node manager: nvm
Terminal context: SSH session on a managed hosting server

The active binaries are:

~/.nvm/versions/node/v24.13.0/bin/node
~/.nvm/versions/node/v24.13.0/bin/npm
~/.nvm/versions/node/v24.13.0/bin/gemini

Steps already tried

I initially had a mixed Node environment with nodenv, a custom .npm-global prefix, and nvm.

I cleaned it up and confirmed that Gemini CLI now runs from the nvm installation only:

which node
which npm
which gemini
node -v
npm -v
gemini --version

Current result:

~/.nvm/versions/node/v24.13.0/bin/node
~/.nvm/versions/node/v24.13.0/bin/npm
~/.nvm/versions/node/v24.13.0/bin/gemini
v24.13.0
11.6.2
0.44.0

Despite this clean setup, the crash still occurs.

Error output

ERROR ioctl(2) failed, EBADF

~/.nvm/versions/node/v24.13.0/lib/node_modules/@google/gemini-cli/node_modules/@lydell/node-pty/unixTerminal.js:243:13

240: if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
241:     throw new Error('resizing must be done using positive cols and rows');
242: }
243: pty.resize(this._fd, cols, rows);
244: this._cols = cols;
245: this._rows = rows;
246: };

- UnixTerminal.resize (.../@google/gemini-cli/node_modules/@lydell/node-pty/unixTerminal.js:243:13)
- _ShellExecutionService.resizePty (.../@google/gemini-cli/bundle/chunk-BE42OOYM.js:320262:30)
- (.../@google/gemini-cli/bundle/interactiveCli-RDMZS6KL.js:6529:31)
- commitHookEffectListMount (.../@google/gemini-cli/bundle/chunk-VUERI7WB.js:5260:30)
- commitPassiveMountOnFiber (.../@google/gemini-cli/bundle/chunk-VUERI7WB.js:6282:29)
- recursivelyTraversePassiveMountEffects (.../@google/gemini-cli/bundle/chunk-VUERI7WB.js:6263:13)

Expected behavior

Gemini CLI should not crash when resizing or initializing the PTY.

If the PTY file descriptor is already closed or invalid, the resize operation should probably be ignored or handled safely instead of throwing a critical error.

Actual behavior

Gemini CLI exits with:

An unexpected critical error occurred: Error: ioctl(2) failed, EBADF

Notes

This looks like resizePty is being called after the underlying PTY file descriptor has already become invalid or closed.

A guard around the resize call, or safer handling of EBADF, may avoid crashing the whole CLI.

What did you expect to happen?

What did you expect to happen?

I expected Gemini CLI to start normally without crashing when initializing or resizing the PTY in an SSH terminal session.

If the PTY file descriptor is invalid or already closed, I would expect the resize operation to fail gracefully instead of terminating the entire CLI with a critical error.

Client information

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ About Gemini CLI │ │ │ │ CLI Version 0.44.0 │ │ Git Commit 1000b33d4 │ │ Model Auto │ │ Sandbox no sandbox │ │ OS linux │ │ Auth Method gemini-api-key │ │ │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Login information

No response

Anything else we need to know?

No response

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…

FAQ

Expected behavior

Gemini CLI should not crash when resizing or initializing the PTY.

If the PTY file descriptor is already closed or invalid, the resize operation should probably be ignored or handled safely instead of throwing a critical error.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING