Skip to content
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

Piping from stdin is broken #5927

Closed
addaleax opened this issue Mar 27, 2016 · 10 comments
Closed

Piping from stdin is broken #5927

addaleax opened this issue Mar 27, 2016 · 10 comments
Labels
process Issues and PRs related to the process subsystem. stream Issues and PRs related to the stream subsystem.

Comments

@addaleax
Copy link
Member

  • Version: master (ace1009 and upwards, everything before is fine)
  • Platform: Linux 4.2.0-34-generic Gitter chat room? #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: stream

Since ace1009 (#5776), stdin is truncated to the first 64kb when piped to some other stream.

Before:

$ head -c 256000 /dev/zero | ./node -e 'process.stdin.pipe(process.stdout)' | wc
      0       0  256000

After:

$ head -c 256000 /dev/zero | ./node -e 'process.stdin.pipe(process.stdout)' | wc
      0       0   65536

This also goes for piping to bl(), and the end event on process.stdin seems to be fired only when the input is smaller than 16384 bytes.

/cc @orangemocha

@mscdex mscdex added stream Issues and PRs related to the stream subsystem. process Issues and PRs related to the process subsystem. labels Mar 27, 2016
@addaleax
Copy link
Member Author

Btw, apparently this only happens with pipes, i.e.

$ head -c 256000 /dev/zero > data
$ ./node -e 'process.stdin.pipe(process.stdout)' < data | wc
      0       0  256000

works just fine.

@Fishrock123
Copy link
Contributor

cc @nodejs/streams

@Fishrock123
Copy link
Contributor

Why it only happens with pipes probably has something to do with what I just posted in #5916 (comment):

<-ing a file into stdin actually results in a fs.ReadStream, rather an a tty.ReadStream, and as such does not inherit from net.Socket, unlike the other possible stdin options:

case 'FILE':
var fs = require('fs');
stdin = new fs.ReadStream(null, { fd: fd, autoClose: false });
break;

@addaleax
Copy link
Member Author

@Fishrock123 Makes sense then, thanks for the info!

@orangemocha
Copy link
Contributor

I will definitely follow up and investigate this, but it might take me a while to fix it.. streams is delicate code, and I am travelling to the VM summit in SF next week. I might end up reverting #5776 while I figure it out, as it seems that this issue is more severe.

Of course, if anyone wants to investigate further please be welcome! As a first step I'd like to see if reverting 4611389 (but not ace1009) makes this problem go away or not.

addaleax referenced this issue Mar 29, 2016
If a pipe is cleaned up (due to unpipe) during a write that
returned false, the source stream can get stuck in a paused state.

Fixes: #2323
PR-URL: #2325
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
evanlucas added a commit to evanlucas/node that referenced this issue Mar 29, 2016
This reverts commit 4611389.

The offending commit broke certain usages of piping from stdin.

Fixes: nodejs#5927
PR-URL: nodejs#5947
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Alexis Campailla <orangemocha@nodejs.org>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@addaleax
Copy link
Member Author

@evanlucas Thanks for taking care of this for now. Would it be a good idea if I tried to write a regression test for this?

@evanlucas
Copy link
Contributor

@addaleax That would definitely be appreciated!

@addaleax
Copy link
Member Author

@evanlucas Done: #5949

addaleax added a commit to addaleax/node that referenced this issue Mar 29, 2016
Check that piping a large chunk of data from `process.stdin`
into `process.stdout` does not lose any data by verifying that
the output has the same size as the input.

This is a regression test for nodejs#5927 and fails for the commits
in the range [ace1009..89abe86).
bnoordhuis pushed a commit that referenced this issue Mar 30, 2016
Check that piping a large chunk of data from `process.stdin`
into `process.stdout` does not lose any data by verifying that
the output has the same size as the input.

This is a regression test for #5927 and fails for the commits
in the range [ace1009..89abe86).

PR-URL: #5949
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
evanlucas pushed a commit that referenced this issue Mar 30, 2016
Check that piping a large chunk of data from `process.stdin`
into `process.stdout` does not lose any data by verifying that
the output has the same size as the input.

This is a regression test for #5927 and fails for the commits
in the range [ace1009..89abe86).

PR-URL: #5949
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
evanlucas pushed a commit that referenced this issue Mar 31, 2016
Check that piping a large chunk of data from `process.stdin`
into `process.stdout` does not lose any data by verifying that
the output has the same size as the input.

This is a regression test for #5927 and fails for the commits
in the range [ace1009..89abe86).

PR-URL: #5949
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@MylesBorins
Copy link
Contributor

@orangemocha I've tried reapplying ace1009 to master and running CI to see if the suite passes on windows https://ci.nodejs.org/job/node-test-commit/2887/

edit: no bueno

MylesBorins pushed a commit that referenced this issue Apr 11, 2016
Check that piping a large chunk of data from `process.stdin`
into `process.stdout` does not lose any data by verifying that
the output has the same size as the input.

This is a regression test for #5927 and fails for the commits
in the range [ace1009..89abe86).

PR-URL: #5949
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@orangemocha
Copy link
Contributor

Thanks @thealphanerd . I am investigating again, teaming up with @joaocgreis and @bzoz, and we have also confirmed that emitting 'pause' on nextTick alone causes this issue.

This is unfortunate, because in some of my testing to fix #5384 I could see 'pause' and 'resume' events being emitted out of order. I have a bad feeling that there might be another set of hidden bugs in Node because of that, but that they are not getting caught by our unit tests.

ryzokuken added a commit to ryzokuken/node that referenced this issue Mar 13, 2018
Rename the tests appropriately alongside mentioning the subsystem
Also, make a few basic changes to make sure the tests conform
to the standard test structure

- Rename test-regress-nodejsGH-9819 to test-crypto-tostring-segfault
- Rename test-regress-nodejsGH-5051 to test-http-addrequest-localaddress
- Rename test-regress-nodejsGH-5727 to test-net-listen-invalid-port
- Rename test-regress-nodejsGH-5927 to test-tty-stdin-pipe
- Rename test-regress-nodejsGH-6235 to test-v8-global-setter

Refs: nodejs#19105
Refs: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#test-structure
lpinca pushed a commit that referenced this issue Mar 13, 2018
Rename the tests appropriately alongside mentioning the subsystem.
Also, make a few basic changes to make sure the tests conform to the
standard test structure.

- Rename test-regress-GH-9819 to test-crypto-tostring-segfault
- Rename test-regress-GH-5051 to test-http-addrequest-localaddress
- Rename test-regress-GH-5727 to test-net-listen-invalid-port
- Rename test-regress-GH-5927 to test-tty-stdin-pipe
- Rename test-regress-GH-6235 to test-v8-global-setter

PR-URL: #19275
Refs: #19105
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Mar 20, 2018
Rename the tests appropriately alongside mentioning the subsystem.
Also, make a few basic changes to make sure the tests conform to the
standard test structure.

- Rename test-regress-GH-9819 to test-crypto-tostring-segfault
- Rename test-regress-GH-5051 to test-http-addrequest-localaddress
- Rename test-regress-GH-5727 to test-net-listen-invalid-port
- Rename test-regress-GH-5927 to test-tty-stdin-pipe
- Rename test-regress-GH-6235 to test-v8-global-setter

PR-URL: #19275
Refs: #19105
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Mar 20, 2018
Rename the tests appropriately alongside mentioning the subsystem.
Also, make a few basic changes to make sure the tests conform to the
standard test structure.

- Rename test-regress-GH-9819 to test-crypto-tostring-segfault
- Rename test-regress-GH-5051 to test-http-addrequest-localaddress
- Rename test-regress-GH-5727 to test-net-listen-invalid-port
- Rename test-regress-GH-5927 to test-tty-stdin-pipe
- Rename test-regress-GH-6235 to test-v8-global-setter

PR-URL: #19275
Refs: #19105
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
Rename the tests appropriately alongside mentioning the subsystem.
Also, make a few basic changes to make sure the tests conform to the
standard test structure.

- Rename test-regress-nodejsGH-9819 to test-crypto-tostring-segfault
- Rename test-regress-nodejsGH-5051 to test-http-addrequest-localaddress
- Rename test-regress-nodejsGH-5727 to test-net-listen-invalid-port
- Rename test-regress-nodejsGH-5927 to test-tty-stdin-pipe
- Rename test-regress-nodejsGH-6235 to test-v8-global-setter

PR-URL: nodejs#19275
Refs: nodejs#19105
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants