On Friday, March 29, 2013 10:54:38 AM UTC-6, Andrew Hart wrote:
> These both read until cat stops, even though they aren't doing anything
> with the input (not sending it to stdout). Why is reading from a pipe
> different from reading from a TTY?
> cat| node -e
> 'process.stdin.pipe(process.stdout);setTimeout(function(){process.stdin.unpipe();},
>
> 100);'
> cat| node -e
> 'process.stdin.pipe(process.stdout);process.nextTick(function(){process.stdin.unpipe();});'
>
> This terminates immediately. Finally, this is what I'd expect; unpipe
> undoes the effect of pipe and there is nothing to do but terminate. But why
> is reading from a yes-pipe different from reading from a cat-pipe?
> yes| node -e
> 'process.stdin.pipe(process.stdout);process.nextTick(function(){process.stdin.unpipe();});'
>
>
Rebuilding node with some extra calls to debug inside net.js and running
again with NODE_DEBUG=net showed that the yes-pipe was going fast enough to
cause back-pressure (self.push(buffer.slice(offset, end)) returned false).
The back-pressure causes handle.readStop() to be called. If I just dump
enough input into cat, I'll eventually get back-pressure and node will
terminate.
I can side-step the issue with process.stdin.unref() but
1. That requires the application to track when any portion might be
listening to a given stream -- I'd expect node to do that
2. I don't know that unref() works on streams generally. If stdin happens
to be a tty.ReadStream then it is a net.Socket so it has a documented
unref().
I'd like readable streams for which my application is no longer listening
to not prevent node from terminating. Is that supposed to be the case
already? Is there a documented way to cause that behavior? Would a patch
causing such behavior be welcome?
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.