Skip to content

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

Merged
gireeshpunathil merged 1 commit into
nodejs:masterfrom
gireeshpunathil:close-bifurcated-stdio
Feb 6, 2019
Merged

child_process: close pipe ends that are re-piped#21209
gireeshpunathil merged 1 commit into
nodejs:masterfrom
gireeshpunathil:close-bifurcated-stdio

Conversation

@gireeshpunathil

Copy link
Copy Markdown
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-botnodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label Jun 8, 2018
@addaleax

Copy link
Copy Markdown
Member

Can we add regression tests here?

@jasnell
jasnell requested review from cjihrig and evanlucasJune 9, 2018 00:59
@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

@addaleax - sure.

@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

@addaleax - done, please have a look!

@addaleaxaddaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense!

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@mcollina

Copy link
Copy Markdown
Member

@mcollina

Copy link
Copy Markdown
Member

@evanlucas@cjihrig are you ok with this landing?

@cjihrig

Copy link
Copy Markdown
Contributor

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

@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown

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

@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown

@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
Copy Markdown
MemberAuthor

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

Trott commented Jul 9, 2018

Copy link
Copy Markdown
Member

@gireeshpunathilhttps://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

Trott commented Jul 9, 2018

Copy link
Copy Markdown
Member

(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

@TrottTrott left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Ping... any updates on this one?

@jasnelljasnell added the stalled Issues and PRs that are stalled. label Sep 10, 2018
@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

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

@gireeshpunathilgireeshpunathil removed the stalled Issues and PRs that are stalled. label Feb 3, 2019
@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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.

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

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 reviewFebruary 4, 2019 21:33

Windows is passing

@gireeshpunathilgireeshpunathil 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#9413Fixes: 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>
@gireeshpunathilgireeshpunathil 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:masterFeb 6, 2019
@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

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: #9413Fixes: #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
Copy Markdown
Contributor

FYI: #25988 test is flaky on windows

@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

sure @refack , will have a look.

@targostargos 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_processIssues and PRs related to the child_process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spawn with pipes Second child process doesn't receive data when using the stdout of first child process as stdin of second

9 participants

@gireeshpunathil@addaleax@mcollina@cjihrig@elibarzilay@Trott@jasnell@refack@nodejs-github-bot