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

Use /dev/stdin instead of 0 when using with readFileSync #25

Merged
merged 1 commit into from
Dec 31, 2024
Merged

Conversation

ben-z
Copy link
Member

@ben-z ben-z commented Dec 31, 2024

Sometimes, especially when reading large inputs from stdin, we get the following error:

node:internal/fs/sync:25
  return binding.readFileUtf8(path, stringToFlags(flag));
                 ^

Error: EAGAIN: resource temporarily unavailable, read
    at Object.readFileUtf8 (node:internal/fs/sync:25:18)
    at Object.readFileSync (node:fs:441:19)
    at /usr/local/lib/node_modules/@watonomous/watcloud-emails/dist/cli/index.js:74:44
    at Generator.next (<anonymous>)
    at /usr/local/lib/node_modules/@watonomous/watcloud-emails/dist/cli/index.js:9:71
    at new Promise (<anonymous>)
    at __awaiter (/usr/local/lib/node_modules/@watonomous/watcloud-emails/dist/cli/index.js:5:12)
    at Command.<anonymous> (/usr/local/lib/node_modules/@watonomous/watcloud-emails/dist/cli/index.js:69:41)
    at Command.listener [as _actionHandler] (/usr/local/lib/node_modules/@watonomous/watcloud-emails/node_modules/commander/lib/command.js:542:17)
    at /usr/local/lib/node_modules/@watonomous/watcloud-emails/node_modules/commander/lib/command.js:1502:14 {
  errno: -11,
  code: 'EAGAIN',
  syscall: 'read'
}

This appears to be because process.stdin.fd only operates on nonblocking mode. This PR accesses /dev/stdin directly instead of using 0.

References:

@ben-z ben-z merged commit 764e4a7 into main Dec 31, 2024
1 check passed
@ben-z ben-z deleted the benz/stdin branch December 31, 2024 06:30
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.

1 participant