Skip to content

child_process: add 'overlapped' stdio flag - #29412

Closed
tarruda wants to merge 4 commits into
nodejs:masterfrom
tarruda:expose-stdio-overlapped-pipe
Closed

child_process: add 'overlapped' stdio flag#29412
tarruda wants to merge 4 commits into
nodejs:masterfrom
tarruda:expose-stdio-overlapped-pipe

Conversation

@tarruda

@tarrudatarruda commented Sep 2, 2019

Copy link
Copy Markdown
Contributor

The 'overlapped' value sets the UV_OVERLAPPED_PIPE libuv flag in the child process stdio.

Fixes: #29238

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

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. child_process Issues and PRs related to the child_process subsystem. labels Sep 2, 2019
@tarruda
tarrudaforce-pushed the expose-stdio-overlapped-pipe branch from 9bbddd4 to 57c0f01CompareSeptember 2, 2019 19:00
@tarrudatarruda changed the title child_process: Add 'pipe+overlapped' stdio flagchild_process: add 'pipe+overlapped' stdio flagSep 2, 2019
@mscdex

Copy link
Copy Markdown
Contributor

Why not just always set UV_OVERLAPPED_PIPE for 'pipe' instead? Are there any drawbacks/incompatibilities with that?

@tarruda

Copy link
Copy Markdown
ContributorAuthor

Why not just always set UV_OVERLAPPED_PIPE for 'pipe' instead? Are there any drawbacks/incompatibilities with that?

Yes, it can possibly break existing programs that run child process that are not prepared for overlapped I/O: libuv/libuv#95 (comment)

@tarruda
tarrudaforce-pushed the expose-stdio-overlapped-pipe branch from 57c0f01 to d4eb7bcCompareSeptember 2, 2019 19:55
@mscdex

Copy link
Copy Markdown
Contributor

Ok, perhaps we can just shorten the name to 'overlapped' instead?

@tarruda

tarruda commented Sep 3, 2019

Copy link
Copy Markdown
ContributorAuthor

Ok, perhaps we can just shorten the name to 'overlapped' instead?

Added a fixup. If this is acceptable I will squash and edit the commit message.

@tarrudatarruda changed the title child_process: add 'pipe+overlapped' stdio flagchild_process: add 'overlapped' stdio flagSep 3, 2019
@tarruda
tarrudaforce-pushed the expose-stdio-overlapped-pipe branch from 0a5b520 to 196c6eaCompareSeptember 3, 2019 12:59
@mscdex

Copy link
Copy Markdown
Contributor

Can you also add a test for this?

@tarruda

Copy link
Copy Markdown
ContributorAuthor

Can you also add a test for this?

Do you have any suggestions on how I should proceed to testing this?

The new option simply activates the UV_OVERLAPPED_PIPE libuv flag, is there any existing test infrastructure to verify that the correct flags were passed by the new option? I couldn't find any reference to UV_CREATE_PIPE in the tests, so I imagine the answer is "no".

I suppose I could just add a functional test that verifies overlapped I/O on the child process, but that would probably be duplicating one of the libuv tests.

Also, the code path should be close to the one followed by the'pipe' value. Would it be enough to copy one of the 'pipe' tests but pass 'overlapped' instead?

@mscdex

Copy link
Copy Markdown
Contributor

At the very least there should be a test that specifying 'overlapped' (via stdio: 'overlapped' or manually expanded out to stdio: ['overlapped', 'overlapped', 'overlapped']) does not throw an exception (since the code currently throws on unsupported modes).

Fishrock123
Fishrock123 previously approved these changes Sep 5, 2019
@Fishrock123
Fishrock123 dismissed their stale reviewSeptember 5, 2019 18:00

Pending tests as mscdex mentioned.

@tarruda

Copy link
Copy Markdown
ContributorAuthor

At the very least there should be a test that specifying 'overlapped' (via stdio: 'overlapped' or manually expanded out to stdio: ['overlapped', 'overlapped', 'overlapped']) does not throw an exception (since the code currently throws on unsupported modes).

👍

I also want to add a test that runs a C++ windows program that will not work if the stdio handles are not overlapped pipes.

@TrottTrott added the wip Issues and PRs that are still a work in progress. label Sep 6, 2019
@tarruda
tarrudaforce-pushed the expose-stdio-overlapped-pipe branch 5 times, most recently from 31ac422 to e06685eCompareSeptember 6, 2019 21:46
@tarruda

Copy link
Copy Markdown
ContributorAuthor

I've added "overlapped-checker", a program which is used to verify the FILE_FLAG_OVERLAPPED status from the child. The new test uses this program to verify that the flag is correctly passed.

@tarruda
tarrudaforce-pushed the expose-stdio-overlapped-pipe branch 3 times, most recently from 9ad1420 to a28f5a3CompareSeptember 6, 2019 23:17
@tarruda

Copy link
Copy Markdown
ContributorAuthor

PR ready for final review.

@TrottTrott removed the wip Issues and PRs that are still a work in progress. label Sep 7, 2019
@tarruda
tarrudaforce-pushed the expose-stdio-overlapped-pipe branch 2 times, most recently from c654e7a to 7094378CompareDecember 16, 2020 11:51
@tarruda

Copy link
Copy Markdown
ContributorAuthor

Following @joaocgreis suggestion on how to make the test find overlapped-checker.exe:

To move forward, if I'm right about this, the easiest way is to find overlapped-checker relative to the executable, like what is done for openssl-cli in

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tarruda

Copy link
Copy Markdown
ContributorAuthor

it seems @joaocgreis's suggestion worked, rebasing on master a squashing the fixup

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RSLGTM because Ben approved it already, but I'd feel more confident if we can get more approvals from other collaborators before landing.

@tarruda

Copy link
Copy Markdown
ContributorAuthor

@aduh95 Not sure if it helps, but I can try to explain the PR to make you more confident about merging.

The "overlapped" stdio option is simply exposing libuv's UV_OVERLAPPED_PIPE, which itself is a wrapper around FILE_FLAG_OVERLAPPED win32 flag. All this flag does it enable non-blocking I/O on child process's std handles and has no effect on Unix systems (it is the same as "pipe" on Unix).

Most of the code in the PR is dedicated to testing that the flag is passed correctly (AFAIR, libuv doesn't have any test covering it). The way the test works is that it will hang if the FILE_FLAG_OVERLAPPED flag is not passed to the child process. If you want, I can push a temporary commit that will modify the test to pass pipe instead of overlapped and we can see the test hang.

@tarruda

Copy link
Copy Markdown
ContributorAuthor

@aduh95 I've added a temporary commit that removes the "overlapped" flag. If you request-ci, we should see windows test hang

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation, it's clear to me now.

Can you remove the timer from the test please? There is a default timeout set by the test.py script, so the timeout can be customized by the test runner.

node/tools/test.py

Lines 1333 to 1334 in e57d8af

result.add_option("-t", "--timeout", help="Timeout in seconds",
default=120, type="int")

Comment threadtest/parallel/test-child-process-stdio-overlapped.js Outdated
Comment threadtest/parallel/test-child-process-stdio-overlapped.js Outdated
@aduh95

Copy link
Copy Markdown
Contributor

@tarruda Do you want to revert 45e83ab to have this ready to land?

@tarruda

Copy link
Copy Markdown
ContributorAuthor

@tarruda Do you want to revert 45e83ab to have this ready to land?

Removed it and added a fixup with the timeout removal on the tests

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tarruda

Copy link
Copy Markdown
ContributorAuthor

@aduh95node-test-linux-linked-debug failed, but it seems unrelated to this PR. Logs show that the ld process was killed during linking of cctest

@aduh95

aduh95 commented Dec 31, 2020

Copy link
Copy Markdown
Contributor

@aduh95node-test-linux-linked-debug failed, but it seems unrelated to this PR. Logs show that the ld process was killed during linking of cctest

Probably unrelated indeed, it happens sometimes. I've kicked off another CI to make sure.

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

Copy link
Copy Markdown
Contributor

Landed in 25b21e4 🎉

@tarruda

Copy link
Copy Markdown
ContributorAuthor

Thanks @aduh95@joaocgreis@bnoordhuis for the help with this PR

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.c++Issues and PRs that require attention from people who are familiar with C++.child_processIssues and PRs related to the child_process subsystem.review wantedPRs that need reviews.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creation of full duplex pipe via spawn causes deadlock on Windows

10 participants

@tarruda@mscdex@Trott@gireeshpunathil@nodejs-github-bot@bnoordhuis@Fishrock123@jasnell@aduh95@richardlau