Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
child_process: set stdin properties when execed#2336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
When a child process is created, the `stdin` will not have `isTTY`, `isRaw` and `setRawMode` properties. Because, `uv_guess_handle` in `guessHandleType` call returns `PIPE` for fd 0. So, we create a `net.Socket` and return. But normally it will return `TTY` and we create `tty.ReadStream` and return where all those properties are properly set. This path explicitly sets the above mentioned properties on the returned socket object. Fixes: nodejs#2333 PR-URL: nodejs#2336
thefourtheye commented Aug 9, 2015
silverwind commented Aug 9, 2015
Hmm, I'm just getting 4x undefined still after this patch on OS X. What OS are you on? |
thefourtheye commented Aug 9, 2015
@silverwind Oh, I am using Ubuntu 14.04.2 |
silverwind commented Aug 9, 2015
What does my test case print for you? I'll try this on linux too, building will take a while though. |
thefourtheye commented Aug 9, 2015
Your testcase prints |
silverwind commented Aug 9, 2015
Shouldn't it like print those properties? (parent prints child's stdout, which logs them) :) |
silverwind commented Aug 9, 2015
Oh wait I'm dumb. I need to supply the built binary to |
thefourtheye commented Aug 9, 2015
@silverwind You meant after the fix? It prints |
silverwind commented Aug 9, 2015
Yeah, works as expected now. Let's see what the CI says. |
thefourtheye commented Aug 9, 2015
@silverwind It fails only in Windows, as of now, but that is because the splitting with |
silverwind commented Aug 9, 2015
Also breaks the REPL it seems. |
thefourtheye commented Aug 9, 2015
Oh, which OS? I couldn't see any REPL failures till now. |
silverwind commented Aug 9, 2015
OS X: |
thefourtheye commented Aug 9, 2015
Ah, it breaks in Ubuntu 14.04.02 as well. Till now they were checking if Interface.prototype._setRawMode=function(mode){if(typeofthis.input.setRawMode==='function'){returnthis.input.setRawMode(mode);}};Should this be considered as a breaking change and the repl should also be fixed? Because, Socket objects can not be considered as raw devices AFAIK. |
silverwind commented Aug 9, 2015
You could wrap in a I'm not understanding yet why you call it a Socket. Isn't stdin basically just a readable stream from fd 0? |
thefourtheye commented Aug 9, 2015
Not if |
silverwind commented Aug 9, 2015
Hmm, wouldn't it be better to set the missing properties just in the PIPE case then? Seems to be safer to me. |
silverwind commented Aug 9, 2015
Something like this maybe: diff --git a/src/node.js b/src/node.js index dfe3599..347d424 100644 --- a/src/node.js+++ b/src/node.js@@ -649,8 +649,9 @@ var tty_wrap = process.binding('tty_wrap'); var fd = 0; + var handleType = tty_wrap.guessHandleType(fd);- switch (tty_wrap.guessHandleType(fd)){+ switch (handleType){ case 'TTY': var tty = NativeModule.require('tty'); stdin = new tty.ReadStream(fd,{@@ -717,11 +718,14 @@ stdin._handle.readStop()}); - stdin.isTTY = true;- stdin.isRaw = false;- stdin.setRawMode = function setRawMode(){- throw new Error('Not a raw device');- };+ // set the missing TTY properties when spawned through child_process.exec+ if (handleType === 'PIPE'){+ stdin.isTTY = true;+ stdin.isRaw = false;+ stdin.setRawMode = function setRawMode(){+ throw new Error('Not a raw device');+ };+ } return stdin}); |
thefourtheye commented Aug 9, 2015
But the properties will be still missing for the NET case, right? |
silverwind commented Aug 9, 2015
Yeah. I'm not even sure what a NET handle would be. A quick look at |
silverwind commented Aug 9, 2015
I think we're confusing something. It's |
thefourtheye commented Aug 9, 2015
Hmmm I am on mobile now. I'll also go through the code once, with your inputs, in the morning. |
silverwind commented Aug 9, 2015
Sure, here's what I propose: diff --git a/src/node.js b/src/node.js index dfe3599..7fe4c48 100644 --- a/src/node.js+++ b/src/node.js@@ -666,7 +666,6 @@ break; case 'PIPE': - case 'TCP': var net = NativeModule.require('net'); // It could be that process has been started with an IPC channel @@ -688,6 +687,13 @@ } // Make sure the stdin can't be `.end()`-ed stdin._writableState.ended = true; ++ // Add missing TTY properties+ stdin.isTTY = false;+ stdin.isRaw = false;+ stdin.setRawMode = function setRawMode(){+ throw new Error('Not a raw device');+ }; break; default: @@ -717,12 +723,6 @@ stdin._handle.readStop()}); - stdin.isTTY = true;- stdin.isRaw = false;- stdin.setRawMode = function setRawMode(){- throw new Error('Not a raw device');- };- return stdin}); |
silverwind commented Aug 9, 2015
I'm pondering if it's actually worth to do the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks incorrect to me. .isTTY should only be true when stdin refers to a real tty, not when it's a file/pipe/socket/etc.
You could wrap it in a if (!process.stdin.hasOwnProperty('isTTY')){... } block, although that feels kind of icky (and the fact that .isTTY is an own property is something of an implementation detail, so if (!('isTTY' in process.stdin)){.. } is probably more correct.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, stdin.isTTY should definitely be false in the PIPE case. I corrected that in my latest diff suggestion.
The whole change is more of a correctness thing. Most scripts do just if (stdin.isTTY), in which case it wouldn't matter if it's undefined or false.
jbergstroem commented Aug 9, 2015
The FreeBSD machine times out, not sure if relevant (can't check right now). |
silverwind commented Aug 10, 2015
@thefourtheye I'll do a PR which supersedes this one if you don't mind. |
thefourtheye commented Aug 10, 2015
@silverwind Oh no problem :-) I ll close this. |
rafaelcastrocouto commented Mar 5, 2016
Hey guys, we are having an error at devtool related to |
bnoordhuis commented Mar 5, 2016
@rafaelcastrocouto How about you file a new issue instead of hijacking an existing pull request? |
rafaelcastrocouto commented Mar 5, 2016
sorry @bnoordhuis ... in my defense I just wanted some advice and I really don't think this is a node issue. Since the subject of this issue seems very related to my problem I just thought someone could easily point how to solve it. I'll keep looking ... thx and sorry again |
bnoordhuis commented Mar 6, 2016
@rafaelcastrocouto If you have a general support question, try https://github.com/nodejs/help/issues. This issue tracker is pretty high-volume, that's why we try to keep it focused. |
rafaelcastrocouto commented Mar 6, 2016
Thx a lot @bnoordhuis ... nodejs/help#105 |
When a child process is created, the
stdinwill not haveisTTY,isRawandsetRawModeproperties. Because,uv_guess_handleinguessHandleTypecall returnsPIPEfor fd 0. So, we create anet.Socketand return. But normally it will returnTTYand we createtty.ReadStreamand return where all those properties are properly set.This path explicitly sets the above mentioned properties on the returned
socket object.
Fixes: #2333