You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The process never ends when piping the stdin to a child process #2276
If I remove the process.stdin.pipe(ps.stdin) line, the main process is ended, but the stdin data is not piped anymore.
Why isn't the main process ended when the ps child process is ended? How can I solve this problem?
An ugly solution would be:
ps.on("close",process.exit.bind(process));
I don't like this, because I don't really want to force the main process to be closed, but I want to be closed naturally (e.g. having setTimeout(function(){}, 1000) you wait 1000ms and then the process ends).
I tried to ps.stdin.close() in ps.on("close", cb). It didn't work... 😢
changed the title [-]NodeJS process never ends when piping the stdin to a child process[/-][+]The process never ends when piping the stdin to a child process[/+]on Jul 30, 2015
I'm not sure, but I guess we could say that if the stdin data is not consumed in the child process, then the main process never ends, even the child process does.
I'm a bit confused by the current state of this, you seem to show this is not a problem with cat, but is with ps, in which case the problem isn't with the node parent but with the behaviour of the non-node child, isn't it?
ps is special, and has odd behaviour wrt. to stdin, cf #24327 (comment).
Can you provide a small self-contained example and a description of how the examples behaviour differs from your expectation?
Activity
targos commentedon Jul 30, 2015
Your example works fine with a command that uses stdin like
cat:We may need more information about the context of your problem, in order to help further.
Fishrock123 commentedon Jul 30, 2015
Does
psactually consume the stdin that is piped to it?Edit: Maybe
psdoesn't close when it's being piped to unless you tell it to?IonicaBizau commentedon Jul 30, 2015
@targos Interesting! If I pipe data to the process, it's closed:
The code is:
And the result is:
If I don't pipe anything, the process is not closed, which is fine in this case because the child process is not closed (it still listens for data).
However, in the
pscase (just replacecatwithpsin the code above) there is a strange behavior:Why does the EPIPE error appears randomly?
I'm happy to provide more information, just ask me. 😸
@Fishrock123 Yeah, probable it doesn't use the stdin data, but the child process is closed -- while the parent still remains alive.
[-]NodeJS process never ends when piping the stdin to a child process[/-][+]The process never ends when piping the stdin to a child process[/+]IonicaBizau commentedon Aug 4, 2015
I'm not sure, but I guess we could say that if the stdin data is not consumed in the child process, then the main process never ends, even the child process does.
IonicaBizau commentedon Oct 8, 2015
Any feedback on this?
Fishrock123 commentedon Oct 9, 2015
@IonicaBizau hmmm, that looks like #947?
(Which fwiw, is a pretty tricky issue.)
IonicaBizau commentedon Oct 9, 2015
@Fishrock123 Ah, actually, yes. Thanks.
masaeedu commentedon Nov 12, 2018
I'm still seeing this issue in Node v10.3.0, was this supposed to be resolved in #947?
masaeedu commentedon Nov 12, 2018
The issue being that if you create a child process and pipe the parent's
stdinto thechild, the parent never dies even if the child does.sam-github commentedon Nov 13, 2018
I'm a bit confused by the current state of this, you seem to show this is not a problem with
cat, but is withps, in which case the problem isn't with the node parent but with the behaviour of the non-node child, isn't it?psis special, and has odd behaviour wrt. to stdin, cf #24327 (comment).Can you provide a small self-contained example and a description of how the examples behaviour differs from your expectation?