sourcecred / widgets

Other
2 stars 3 forks source link

Odd bug reading from stdin #14

Open Beanow opened 5 years ago

Beanow commented 5 years ago

I've got a script where I'm directly piping sourcecred score into widgets' bin/contributor-wall-svg.js here: https://github.com/sfosc/sourcecred/blob/70dbdb6621cbaa4a2a6280a8f9d53b584d0b10f8/scripts/rebuild-site.sh#L76

In some cases (like the current sfosc/sfosc repo) this causes an EAGAIN error, both locally and on the CI build: https://drone.sfosc.robin-it.com/sfosc/sourcecred/30/1/2

Generating sfosc-sfosc-contributors.svg
Error: EAGAIN: resource temporarily unavailable, read
    at Object.readSync (fs.js:498:3)
    at tryReadSync (fs.js:332:20)
    at readFileSync (fs.js:369:19)
    at Object.<anonymous> (/drone/src/widgets/bin/contributor-wall-svg.js:26:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
Generating sfosc-wizard-contributors.svg
Generating sfosc-sourcecred-contributors.svg 

Strangely enough it can be resolved by writing the scores to a file and using the < operator to read this file instead of | to pipe directly from the sourcecred scores output.

I can't explain why this is happening exactly yet, my suspicion is it may be related to how piping gets buffered vs reading from files. Either way the current read from stdin seems brittle.

Beanow commented 5 years ago

The workaround: https://github.com/sfosc/sourcecred/commit/45dd1bf32eb7069c2294f119ab02e2fb524e09d6

Working build output: https://drone.sfosc.robin-it.com/sfosc/sourcecred/31/1/2

Beanow commented 5 years ago

I was able to reproduce it more reliably using the attached scores file. sfosc-sfosc-scores.zip

$ widgets/bin/contributor-wall-svg.js > sfosc-sfosc-contributors.svg < sfosc-sfosc-scores.json
# No problem
$ cat sfosc-sfosc-scores.json | widgets/bin/contributor-wall-svg.js > sfosc-sfosc-contributors.svg
# No problem
$ echo "$(cat sfosc-sfosc-scores.json)" | widgets/bin/contributor-wall-svg.js > sfosc-sfosc-contributors.svg
# Error: EAGAIN: resource temporarily unavailable, read