Fix EAGAIN crash when reading --standard-json input from a pipe - #795
Open
cavdarahmet wants to merge 1 commit into
Open
Fix EAGAIN crash when reading --standard-json input from a pipe#795cavdarahmet wants to merge 1 commit into
cavdarahmet wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #460
fs.readFileSync(process.stdin.fd)can throwEAGAINwhen stdin is a pipethat 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/endevents instead, whichhandles 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).