Skip to content

bug(factory): EAGAIN crash when stdin is non-blocking but empty #311

Description

@margaretjgu

Summary

Any command with an input schema (the entire es namespace) crashes with an unhandled EAGAIN exception when run from IDE terminals (Cursor, VS Code integrated terminal), CI pipelines, or any environment where process.stdin.isTTY is falsy but no data is piped.

Steps to reproduce

Run any ES API command interactively from an IDE terminal (e.g. VS Code or Cursor):

elastic es cat indices

Actual behaviour

Error: EAGAIN: resource temporarily unavailable, read
    at readFileSync (node:fs:440:20)
    at stdinReader (dist/factory.js:35)
    at Command.<anonymous> (dist/factory.js:479)

Expected behaviour

Command executes normally with no stdin data.

Root cause

src/factory.ts uses readFileSync(0, 'utf-8') (synchronous fd-0 read) when !process.stdin.isTTY. IDE terminals set stdin to non-blocking mode, so the synchronous read fails immediately with EAGAIN rather than blocking.

Fix

Wrap stdinReader() in a try-catch and treat EAGAIN / EBADF as "no stdin data available":

} else if (!process.stdin.isTTY) {
  let raw: string
  try {
    raw = stdinReader()
  } catch (e: unknown) {
    const code = (e as NodeJS.ErrnoException).code
    if (code === 'EAGAIN' || code === 'EBADF') raw = ''
    else throw e
  }
  if (raw.trim().length > 0) { ... }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions