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

Twirpscript fails with Error: EAGAIN #7

Closed
4nte opened this issue Nov 16, 2021 · 4 comments
Closed

Twirpscript fails with Error: EAGAIN #7

4nte opened this issue Nov 16, 2021 · 4 comments

Comments

@4nte
Copy link
Contributor

4nte commented Nov 16, 2021

When running twirpscript this error occurs randomly, with no apparent cause.

Twirpscript was working fine for a while, then suddenly I started getting this error out of a blue.
Sometimes I need to run twirpscript few times in a row before it succeeds without the error. As if I have to wait for some lock to release, but there should be none.

node:internal/fs/utils:344
    throw err;
    ^

Error: EAGAIN: resource temporarily unavailable, write
    at Object.writeSync (node:fs:884:3)
    at writeFileSync (node:fs:2159:26)
    at Object.<anonymous> (<PROJECT_DIR_REDACTED>/proto/node_modules/twirpscript/dist/compiler.js:29:24)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -11,
  syscall: 'write',
  code: 'EAGAIN'
}

@4nte
Copy link
Contributor Author

4nte commented Nov 16, 2021

Upon further investigation, it seems that the issue is caused by writing "large" buffers synchronously to stdout.

I tested this by removing half of my proto files and running twirpscript successfully 100% of the time.
When I add more proto files, twirpscript starts consistently failing with the error above.

Refactoring

// Fails with EAGAIN when buffer too large
writeFileSync(process.stdout.fd, response.serializeBinary());
// Succeeds with large buffers
process.stdout.write(Buffer.from(response.serializeBinary().buffer))

@tatethurston
Copy link
Owner

tatethurston commented Nov 16, 2021

Hey @4nte thanks for reporting this issue. What version of node are you using? Also, do you have an example repo that I could take a look at?

Doing some digging I found this: nodejs/node#7439 (comment). I suspect that is the issue.

tatethurston pushed a commit that referenced this issue Nov 17, 2021
@4nte
Copy link
Contributor Author

4nte commented Nov 17, 2021

I'm running node v16.11.0 on Manjaro 21.1.6

Here's an example repo.
https://github.com/4nte/twirpscript-eagain-example

Steps to reproduce:

  1. Run twirpscript

tatethurston added a commit that referenced this issue Nov 17, 2021
@tatethurston
Copy link
Owner

@4nte Thanks so much for the repro. I've published v0.0.22 which resolves the issue in your example. Let me know if you run into anything else!

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

No branches or pull requests

2 participants