This repository has been archived by the owner. It is now read-only.

Referencing process.stdin causes EPIPE #7481

Closed
mafintosh opened this Issue Apr 18, 2014 · 8 comments

Comments

Projects
None yet
6 participants
@mafintosh
Member

mafintosh commented Apr 18, 2014

I recently ran in to this very strange bug. I have a node program that produces a decent amount of output to stdout. When I piped it to another another program it would start failing with EPIPE. After some debugging I found out that the EPIPE was caused by a reference to process.stdin.

To illustrate the problem I've boiled it down to the following test-case.

var stdin = process.stdin; // this line breaks things

var buf = new Buffer(512);
var cnt = 0;

buf.fill(97); // fill it with 'a' for nicer output

setInterval(function() {
    console.log(buf.toString()+' #'+(cnt++));
}, 5);

Save the above program as example.js and run

node example.js | cat -

The program fails almost instantly with

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write EPIPE
    at errnoException (net.js:904:11)
    at Object.afterWrite (net.js:720:19)

BUT! If we remove process.stdin from the start of the program:

var buf = new Buffer(512);
var cnt = 0;

buf.fill(97);

setInterval(function() {
    console.log(buf.toString()+' #'+(cnt++));
}, 5);

And rerun the example the program keeps running without errors and produces a lot of output.

Is this intended behaviour? After a bit of digging I noticed that process.stdin is actually a getter which is probably why I'm seeing the weird side effects.

@indutny

This comment has been minimized.

Member

indutny commented Apr 18, 2014

I guess this is a bug... Could you please try producing a single js file that reproduces it? You may use child_process and some other core modules.

@mafintosh

This comment has been minimized.

Member

mafintosh commented Apr 18, 2014

I've made a test case here, https://gist.github.com/mafintosh/11063733
Its failing on OSX 10.9.2.

@mafintosh

This comment has been minimized.

Member

mafintosh commented Apr 18, 2014

I'm on node 0.10.26 btw.

@tjfontaine

This comment has been minimized.

tjfontaine commented Apr 30, 2014

I cannot replicate this issue, where are you getting your node binary from? and what other configuration information about your environment?

node -v
v0.10.26
node s.js | cat -
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #1

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa #2
@mafintosh

This comment has been minimized.

Member

mafintosh commented Apr 30, 2014

I downloaded the osx binary from http://nodejs.org/download/. I just reproduced it again using my gist.

node -v
v0.10.26
bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
uname -a
Darwin brunhilde.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64

Also we were getting this issue in dat and I had @maxogden reproduce it using my test case so maybe he can share some info about his env as well

@mafintosh

This comment has been minimized.

Member

mafintosh commented Apr 30, 2014

I couldn't reproduce it using ubuntu 12.04 though - only on osx

@mietek

This comment has been minimized.

mietek commented Aug 29, 2014

This problem has been around for a while.

@Fishrock123

This comment has been minimized.

Member

Fishrock123 commented Dec 22, 2016

I can't repo this (using macOS 10.10.5) on master or 0.10.48 either. It is possible there was a streams bug that was fixed, or perhaps there was a bug between your specific terminal version and cat.

(This error usually points to the fd being closed IIRC.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.