GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — child_process: set stdin properties when `exec`ed by thefourtheye · Pull Request #2336 · nodejs/node

Conversation

@thefourtheye

@thefourtheye thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

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: #2333

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye
thefourtheye force-pushed the fix-for-2333 branch from f6efdee to 166a05e Compare August 9, 2015 16:13
@thefourtheye thefourtheye added the child_process Issues and PRs related to the child_process subsystem. label Aug 9, 2015
@thefourtheye
thefourtheye force-pushed the fix-for-2333 branch from 166a05e to 1d0a4ec Compare August 9, 2015 16:15
@thefourtheye
child_process: set stdin properties when execed
5d70af8
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
thefourtheye force-pushed the fix-for-2333 branch from 1d0a4ec to 5d70af8 Compare August 9, 2015 16:15
@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

CI Run: https://jenkins-iojs.nodesource.com/job/node-test-pull-request/60/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Hmm, I'm just getting 4x undefined still after this patch on OS X. What OS are you on?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

@silverwind Oh, I am using Ubuntu 14.04.2

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

What does my test case print for you? I'll try this on linux too, building will take a while though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

Your testcase prints undefined four times, one in each line.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Shouldn't it like print those properties? (parent prints child's stdout, which logs them) :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Oh wait I'm dumb. I need to supply the built binary to exec of course :D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

@silverwind You meant after the fix? It prints true, false, [Function setRawMode] and undefined

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Yeah, works as expected now. Let's see what the CI says.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

@silverwind It fails only in Windows, as of now, but that is because the splitting with os.EOL. I ll change it to split with \n only.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Also breaks the REPL it seems.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

Oh, which OS? I couldn't see any REPL failures till now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye
Splitting with \n
fa32a5b
@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

OS X:

$ ./iojs
node.js:723
        throw new Error('Not a raw device');
        ^

Error: Not a raw device
    at ReadStream.setRawMode (node.js:723:15)
    at REPLServer.Interface._setRawMode (readline.js:173:23)
    at REPLServer.Interface (readline.js:133:10)
    at new REPLServer (repl.js:229:16)
    at Object.exports.start (repl.js:467:14)
    at Object.createRepl [as createInternalRepl] (internal/repl.js:60:21)
    at startup (node.js:127:19)
    at node.js:958:3
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

Ah, it breaks in Ubuntu 14.04.02 as well. Till now they were checking if setRawMode is a function or not, before calling it, in readline

Interface.prototype._setRawMode = function(mode) {
  if (typeof this.input.setRawMode === 'function') {
    return this.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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

You could wrap in a try instead of checking for a function for the REPL.

I'm not understanding yet why you call it a Socket. Isn't stdin basically just a readable stream from fd 0?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

Not if tty_wrap.guessHandleType returns PIPE or NET. We return a net.Socket instance in those cases.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Hmm, wouldn't it be better to set the missing properties just in the PIPE case then? Seems to be safer to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

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;
     });
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

But the properties will be still missing for the NET case, right?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Yeah. I'm not even sure what a NET handle would be. A quick look at uv_guess_handle doesn't give an impression it exists. Also I think we should actually set isTTY to false in the PIPE case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

I think we're confusing something. It's 'TCP' we're talking about. Anyway, it doesn't look like uv_guess_handle is able to return UV_TCP either, so I think it can safely be removed from the switch statement. It was added in e99dff4.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 9, 2015

Copy link
Copy Markdown
Contributor Author

Hmmm I am on mobile now. I'll also go through the code once, with your inputs, in the morning.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

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;
     });
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

I'm pondering if it's actually worth to do the setRawMode thing after all, it's possibly breaking as we've seen. isTTY and isRaw are somewhat worthy correctness changes, thought they don't really fix the issue described in sindresorhus/grunt-shell#95 (comment), but that was expected :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed Aug 9, 2015
View reviewed changes
Comment thread src/node.js

@bnoordhuis bnoordhuis Aug 9, 2015

Copy link
Copy Markdown
Member

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.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@silverwind silverwind Aug 9, 2015

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jbergstroem

jbergstroem commented Aug 9, 2015

Copy link
Copy Markdown
Member

The FreeBSD machine times out, not sure if relevant (can't check right now).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Aug 10, 2015

Copy link
Copy Markdown
Contributor

@thefourtheye I'll do a PR which supersedes this one if you don't mind.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Aug 10, 2015

Copy link
Copy Markdown
Contributor Author

@silverwind Oh no problem :-) I ll close this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye closed this Aug 10, 2015
@thefourtheye
thefourtheye deleted the fix-for-2333 branch August 10, 2015 15:43
@rafaelcastrocouto

rafaelcastrocouto commented Mar 5, 2016

Copy link
Copy Markdown

Hey guys, we are having an error at devtool related to stdin that only happens in windows Experience-Monks/devtool#42 and I have no clue how to solve it. Seems like electron "renderer" process.stdin is throwing the Exception: Error: Implement me. Unknown stdin file type! error. Can anyone help? Thx a lot!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Mar 5, 2016

Copy link
Copy Markdown
Member

@rafaelcastrocouto How about you file a new issue instead of hijacking an existing pull request?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rafaelcastrocouto

rafaelcastrocouto commented Mar 5, 2016

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Mar 6, 2016

Copy link
Copy Markdown
Member

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rafaelcastrocouto

rafaelcastrocouto commented Mar 6, 2016

Copy link
Copy Markdown

Thx a lot @bnoordhuis ... nodejs/help#105

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jan 16, 2022
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 solebox/node#27
Open
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 s4sc/node#26
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 GregorFendt/node#20
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 saurabharch/node#25
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 KamilPolivka/node#24
Open
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 erdun/node#44
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 saeedahassan/node#38
Open
[Snyk] Security upgrade marked from 0.3.6 to 4.0.10 olegnn/node#38
Open
@snyk-bot snyk-bot mentioned this pull request Jan 31, 2022
[Snyk] Security upgrade marked from 0.3.19 to 4.0.10 enterstudio/node#25
Open
@snyk-bot snyk-bot mentioned this pull request Jun 24, 2022
[Snyk] Fix for 7 vulnerabilities adamlaska/node#70
Open
@aliscco aliscco mentioned this pull request Dec 1, 2023
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#953
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

child_process Issues and PRs related to the child_process subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@thefourtheye @silverwind @jbergstroem @rafaelcastrocouto @bnoordhuis
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.