Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ensure --stdin flag works when stdin is piped asynchronously #10393

Merged
merged 1 commit into from
May 28, 2018

Conversation

not-an-aardvark
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix

Tell us about your environment

  • ESLint Version: master
  • Node Version: 8.11.1
  • npm Version: 5.6.0

What parser (default, Babel-ESLint, etc.) are you using?

N/A

Please show your full configuration:

N/A

What did you do? Please include the actual source code causing the issue.

This issue is simplest to reproduce with bash:

$ (echo 'a' && sleep 1 && echo 'b') | eslint --stdin --no-eslintrc

(I originally encountered this issue when using curl to fetch a JS file and pipe it to eslint --stdin.)

What did you expect to happen?

I expected ESLint to read stdin until the end (resulting in two lines of input), and then lint those two lines.

What actually happened? Please include the actual, raw output from ESLint.

An error was thrown:

EAGAIN: resource temporarily unavailable, read
Error: EAGAIN: resource temporarily unavailable, read
    at Object.fs.readSync (fs.js:675:18)
    at tryReadSync (fs.js:540:20)
    at Object.fs.readFileSync (fs.js:583:19)
    at Object.<anonymous> (/path/to/eslint/bin/eslint.js:59:53)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

Based on nodejs/node#7439, this probably only occurs on macOS.

What changes did you make? (Give an overview)

This updates bin/eslint.js to avoid accessing the process.stdin getter, which seems to change the state of file descriptor 0.

Is there anything you'd like reviewers to focus on?

Should this be filed as a Node bug instead? Based on nodejs/node#7439, it seems to at least partially be working as intended, but the behavior is somewhat surprising.

@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion labels May 23, 2018
Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

I think we should probably fix here, if the fd property is really undocumented as noted in the issue. I agree that the behavior is surprising, though.

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Agreed we should fix this here regardless of whether it's an upstream bug in Node itself.

@platinumazure platinumazure merged commit 65bce3a into master May 28, 2018
@platinumazure platinumazure deleted the fix-async-stdin-pipe branch May 28, 2018 01:26
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 26, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants