Skip to content

Fix EAGAIN crash when reading --standard-json input from a pipe - #795

Open
cavdarahmet wants to merge 1 commit into
argotorg:masterfrom
cavdarahmet:fix-standard-json-stdin-eagain
Open

Fix EAGAIN crash when reading --standard-json input from a pipe#795
cavdarahmet wants to merge 1 commit into
argotorg:masterfrom
cavdarahmet:fix-standard-json-stdin-eagain

Conversation

@cavdarahmet

Copy link
Copy Markdown

Fixes #460

fs.readFileSync(process.stdin.fd) can throw EAGAIN when stdin is a pipe
that has no data available yet at the moment of the (synchronous) read (see
nodejs/node#7439 for the underlying node.js
limitation). This is not just theoretical: it's been reported multiple times
over the years (2020, 2021, 2024) and is still reproducible today on Node.js
v24.

Fix: read the input via the stdin stream's data/end events instead, which
handles this correctly regardless of how the data arrives on the pipe.

Added a regression test that reproduces the original crash by writing the
standard-json input one byte at a time (a single atomic write does not
trigger the race).

fs.readFileSync(process.stdin.fd) can throw EAGAIN when stdin is a pipe with
no data available yet at the moment of the (synchronous) read. Read the input
via the stdin stream's 'data'/'end' events instead, which handles this
correctly.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Error: EAGAIN: resource temporarily unavailable, read" when using --standard-json flag

1 participant