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

child_process: close pipe ends that are re-piped #21209

Merged

Conversation

gireeshpunathil
Copy link
Member

when t0 and t1 are spawned with t0's outputstream [1, 2] is piped into
t1's input, a new pipe is created which uses a copy of the t0's fd.
This leaves the original copy in Node parent, unattended. Net result is
that when t0 produces data, it gets bifurcated into both the copies

Detect the passed handle to be of 'wrap' type and close after the
native spawn invocation by which time piping would have been over.

Fixes: #9413
Fixes: #18016

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label Jun 8, 2018
@addaleax
Copy link
Member

addaleax commented Jun 8, 2018

Can we add regression tests here?

@jasnell jasnell requested review from evanlucas and cjihrig June 9, 2018 00:59
@gireeshpunathil
Copy link
Member Author

@addaleax - sure.

@gireeshpunathil
Copy link
Member Author

@addaleax - done, please have a look!

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina
Copy link
Member

@mcollina
Copy link
Member

@evanlucas @cjihrig are you ok with this landing?

@cjihrig
Copy link
Contributor

cjihrig commented Jun 25, 2018

In theory this LGTM, but the test introduced by this PR is failing in the CI.

@gireeshpunathil
Copy link
Member Author

my test logic is very straight forward:

echo ${X} | grep '1' | wc -l === 272 where X is 0 to 1000

in windows (with vs2017) this seems to produce 1272.

could it be related to different semantics for vs2017?
could it be related to 4 parallel runs in widnwos? can they influence each other?
could it be related to the unix command emulators (echo, grep, wc etc.) are implemented by vs differently?

I will debug.

@elibarzilay
Copy link

@gireeshpunathil -- what's the status of this? (I tried to see the failure, but looks like the build results expired.)

@gireeshpunathil
Copy link
Member Author

@elibarzilay - it is stuck on (some flavors of) windows failure of its own test case. I am running very low on bandwidth these weeks so kept it in the back burner. If you have some spare time to look at, please see why it fails on windows with VS 2017.

@elibarzilay
Copy link

@gireeshpunathil -- is there a way to re-run a build so I can see the failure? If not, then I'll try doing a Windows build, but that will obviously take more time...

@gireeshpunathil
Copy link
Member Author

sure. @Trott or anyone from build team - can you please help us with running Windows CI against this PR (even better, if this single test is run in Windows) ? I can run full CI but doesn't look like the best way to use machines.

@Trott
Copy link
Member

Trott commented Jul 9, 2018

@gireeshpunathil https://ci.nodejs.org/job/node-stress-single-test/1933/nodes=win2016-1p-vs2017/ If I didn't mess up the parameters, that should build from this PR and run the test 10 times.

@Trott
Copy link
Member

Trott commented Jul 9, 2018

(Although due to the cross-compiling or whatever is used to speed up build in node-test-commit-windows-fanned, it might still be faster to run that. So here's one of those two: https://ci.nodejs.org/job/node-test-commit-windows-fanned/19162/ Again, hopefully I didn't mess up any of the parameters...)

Trott
Trott previously requested changes Jul 10, 2018
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking with a red X just to make sure no one lands this with the test not working on Windows...

@jasnell
Copy link
Member

jasnell commented Sep 10, 2018

Ping... any updates on this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Sep 10, 2018
@gireeshpunathil
Copy link
Member Author

@jasnell - here is where it is stuck: I have developed a test case for this PR, that is consistently failing in some windows flavors (I wasn't successful in recreating it in my local machines). I am unable to correlate the failure with my test logic, as explained in
#21209 (comment).

I should admit I left it unattended for few weeks now. I shall work towards resolving this soon.

@gireeshpunathil gireeshpunathil removed the stalled Issues and PRs that are stalled. label Feb 3, 2019
@gireeshpunathil
Copy link
Member Author

The original test case posed challenge in windows: when the spawned child (cmd.exe) echo text, the echo data command as well as the echo'ed data, both were appearing in the data channel to the parent. If I do echo off, then both were turned off! I could not find a way to suppress the command alone while its output is printed.

So in the new version I made it simple, and platform independent - just write an MB of data in a file, with lines of one KB.

CI: https://ci.nodejs.org/job/node-test-pull-request/20558/

@gireeshpunathil
Copy link
Member Author

CI is good.

@mcollina @jasnell @addaleax @cjihrig - I re-wrote the test case to fit windows; PTAL

@Trott - Windows is passing now, PTAL and dismiss your X mark.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Trott Trott dismissed their stale review February 4, 2019 21:33

Windows is passing

@gireeshpunathil gireeshpunathil added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 5, 2019
when t0 and t1 are spawned with t0's outputstream [1, 2] is piped into
t1's input, a new pipe is created which uses a copy of the t0's fd.
This leaves the original copy in Node parent, unattended. Net result is
that when t0 produces data, it gets bifurcated into both the copies

Detect the passed handle to be of 'wrap' type and close after the
native spawn invocation by which time piping would have been over.

Fixes: nodejs#9413
Fixes: nodejs#18016

PR-URL: nodejs#21209
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@gireeshpunathil gireeshpunathil removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 6, 2019
@gireeshpunathil gireeshpunathil merged commit b1f82e4 into nodejs:master Feb 6, 2019
@gireeshpunathil
Copy link
Member Author

landed as b1f82e4

addaleax pushed a commit that referenced this pull request Feb 6, 2019
when t0 and t1 are spawned with t0's outputstream [1, 2] is piped into
t1's input, a new pipe is created which uses a copy of the t0's fd.
This leaves the original copy in Node parent, unattended. Net result is
that when t0 produces data, it gets bifurcated into both the copies

Detect the passed handle to be of 'wrap' type and close after the
native spawn invocation by which time piping would have been over.

Fixes: #9413
Fixes: #18016

PR-URL: #21209
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@refack
Copy link
Contributor

refack commented Feb 7, 2019

FYI: #25988 test is flaky on windows

@gireeshpunathil
Copy link
Member Author

sure @refack , will have a look.

@targos targos mentioned this pull request Feb 14, 2019
addaleax added a commit to addaleax/node that referenced this pull request Apr 23, 2019
Closing the underlying resource completely has the unwanted side effect
that the stream can no longer be used at all, including passing it
to other child processes.

What we want to avoid is accidentally reading from the stream;
accordingly, it should be sufficient to stop its readable side
manually, and otherwise leave the underlying resource intact.

Fixes: nodejs#27097
Refs: nodejs#21209
gireeshpunathil pushed a commit that referenced this pull request Apr 29, 2019
Closing the underlying resource completely has the unwanted side effect
that the stream can no longer be used at all, including passing it
to other child processes.

What we want to avoid is accidentally reading from the stream;
accordingly, it should be sufficient to stop its readable side
manually, and otherwise leave the underlying resource intact.

Fixes: #27097
Refs: #21209

PR-URL: #27373
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
targos pushed a commit that referenced this pull request Apr 29, 2019
Closing the underlying resource completely has the unwanted side effect
that the stream can no longer be used at all, including passing it
to other child processes.

What we want to avoid is accidentally reading from the stream;
accordingly, it should be sufficient to stop its readable side
manually, and otherwise leave the underlying resource intact.

Fixes: #27097
Refs: #21209

PR-URL: #27373
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
9 participants