-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Consistent EPIPE error writing to stdout when pipe has disconnected (SIGPIPE related?) #3211
Comments
May also be related to #2286? |
OK, so adding a process.on('SIGPIPE', process.exit)
for (var i = 0; i < 100; i++) console.log(i) $ node test.js | head -1
0
$ Still... is this intended behaviour? |
Hmmm, the plots thickens. Trying to exit on process.on('SIGPIPE', process.exit)
process.stdin.resume()
process.stdin.on('data', function(data) { process.stdout.write(data) }) $ for i in {0..100000}; do echo $i; done | node test.js | tail -1
100000 Works as expected, but: $ for i in {0..100000}; do echo $i; done | node test.js | head -1
0
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: write EPIPE
at errnoException (net.js:670:11)
at Object.afterWrite [as oncomplete] (net.js:503:19) Also should be noted that adding a check for |
EPIPE is an expected error. Handle it like you handle other runtime errors, e.g. by attaching an |
Really? So you can't just write to stdout and expect it to work if you happen to pipe it through head or similar? That's... bizarre. I really think you should reconsider this for a second. This error really should be ignored as it was in v0.1.94 and v0.1.6 (see the Node ChangeLog) How can you explain the difference in behaviour when I listen for And is there any documentation that It seems that this was fixed in earlier versions of Node too (cf #2286) and http://comments.gmane.org/gmane.comp.lang.javascript.nodejs/5524 |
Read the thread you link to carefully - it's about ignoring SIGPIPE. SIGPIPE != EPIPE. The first is a signal, the second an error code that syscalls return.
Node by default ignores SIGPIPE signals - unless you install your own handler. |
OK - thanks for the explanation. I guess I just struggled to find any documentation on this being expected behaviour (and any documentation on how to deal with it). |
Created an npm package to deal with this in case anyone else runs into it: https://github.com/mhart/epipebomb |
events.js:141 Error: write EPIPE I am having this error while testing in PHPSpec, any takers ? |
to avoid issues with `| head -n1` See nodejs/node-v0.x-archive#3211 Fixes https://github.com/heroku/toolbelt/issues/164
to avoid issues with `| head -n1` See nodejs/node-v0.x-archive#3211 Fixes https://github.com/heroku/toolbelt/issues/164
to avoid issues with `| head -n1` See nodejs/node-v0.x-archive#3211 Fixes https://github.com/heroku/toolbelt/issues/164
This error seems to happen consistently when any Node program is writing to stdout through a pipe that has disconnected (
SIGPIPE
related?)Here's a very simple example:
Happens on Node v0.6.16, Mac OS X 10.7.3 and Node v0.6.15, Ubuntu 12.04
Is this expected behaviour? Does one need to handle
SIGPIPE
in some special way?I've never seen this in other languages, eg:
$ bash test.sh | head -1 0 $
The text was updated successfully, but these errors were encountered: