Continuing from https://github.com/nodejs/node/issues/9201#issuecomment-255103708. The change from #1233 makes it impossible to write to stdin, something that works in v0.10 and v0.12.
Test case:
var spawn = require('child_process').spawn;
var args = ['-e', 'process.stdin.write("ok\\n")'];
var proc = spawn(process.execPath, args, { stdio: ['pipe'] });
proc.stdin.pipe(process.stdout);
Trace:
$ strace -s1024 -fe write out/Release/node tmp/bug9201.js
...
[pid 25306] write(2, "events.js:160\n throw er; // Unhandled 'error' event\n ^\n\nError: write after end\n at writeAfterEnd (_stream_writable.js:192:12)\n at Socket.Writable.write (_stream_writable.js:243:5)\n at Socket.write (net.js:661:40)\n at [eval]:1:15\n at ContextifyScript.Script.runInThisContext (vm.js:25:33)\n at Object.exports.runInThisContext (vm.js:77:17)\n at Object.<anonymous> ([eval]-wrapper:6:22)\n at Module._compile (module.js:582:32)\n at bootstrap_node.js:345:29\n at _combinedTickCallback (internal/process/next_tick.js:67:7)\n", 554) = 554
...
cc @indutny
sounds like a bug
@bnoordhuis does it actually work on windows? IMO, writing to stdin sounds quite ridiculous... It may not even support writes at all.
Are we actually talking about writing to fd 0, or about writing to the node stream representing it?
The node stream. File descriptor 0 in the example accepts writes just fine, it's a bidirectional UNIX socket.
That's what I was thinking. I'm not sure if we care much about that odd Windows caveat then since I don't think it is possible to hit from this codepath anyways.
@bnoordhuis is it always such thing, though? Is it logical to allow writes to it?
It's not typical but it's also not unheard of in the UNIX world. The current restriction is artificial. All other things being equal, it's better to lift it.
@bnoordhuis Should this remain open?
Just tried it again, it's still unfixed. I've added 'good first contribution' and 'help wanted' labels.
Would love to try tackling this @bnoordhuis, this is my first open source contribution though so I would love some help with getting started. Can you give me an idea of what I should be looking at/doing to get this done?
@nikshepsvn It was introduced in commit 9ae1a61 but that code has since migrated to lib/internal/process/stdio.js.
If you want a real quick test, echo | ./out/Release/node -e 'process.stdin.write(".")' should not throw an error.
FWIW, I'm also fine with closing this. I since learned that python also rejects writes to sys.stdin so at least we're in good company.
I second @bnoordhuis's recommendation to close this as Ruby and Python both open STDIN in read-only mode.
I'll close this out given the lack of activity in terms of making it actually happen and the latest feedback from @bnoordhuis and @JackDanger. If anyone still wants this though feel free to reopen or create an issue/PR.