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

unix,stream: fix getting the correct fd for a handle #6838

Merged
merged 1 commit into from
May 19, 2016

Conversation

saghul
Copy link
Member

@saghul saghul commented May 18, 2016

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

stream

Description of change

On OSX it's possible that the fd is replaced, so use the proper libuv
API to get the correct fd.

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label May 18, 2016
@kzc
Copy link

kzc commented May 18, 2016

This is the test case that does not work as expected with node 4.x and 5.x on Mac:

$ node -e 'require("fs").writeSync(process.stdout._handle.fd, "Hello.\n")'

@cjihrig
Copy link
Contributor

cjihrig commented May 18, 2016

Can we translate that into an actual test to prevent regressions?

@saghul
Copy link
Member Author

saghul commented May 18, 2016

Also, bonus nachos: we're no longer relying on libuv internals to get the fd.

@saghul
Copy link
Member Author

saghul commented May 18, 2016

Can we translate that into an actual test to prevent regressions?

I'm not sure. It would be a OSX only test, which only works if we replaced the fd in the select trick. This could change over time if Apple fixes kqueue to support other fds.

An alternate title would be along the lines of: "use official uv API instead of internal structures".

@mscdex mscdex added the stream Issues and PRs related to the stream subsystem. label May 18, 2016
@kzc
Copy link

kzc commented May 18, 2016

Because it's a tty test it's more difficult to automate. Spawning, piping and redirecting change the code path within node and libuv pertaining to stdout and stderr.

@cjihrig
Copy link
Contributor

cjihrig commented May 18, 2016

OK, well I did verify that the change worked on my OS X box, so LGTM.

@jasnell
Copy link
Member

jasnell commented May 18, 2016

Nice. LGTM. A test would be good but can definitely understand the constraints.

@@ -86,7 +86,7 @@ int StreamWrap::GetFD() {
int fd = -1;
#if !defined(_WIN32)
if (stream() != nullptr)
fd = stream()->io_watcher.fd;
uv_fileno(reinterpret_cast<uv_handle_t*>(stream()), &fd);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

I think you might as well remove the #if !defined(_WIN32) guard now.

Copy link
Member Author

Choose a reason for hiding this comment

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

On Windows that's a HANDLE*, and while it can be cast to an int because only 32 bits are used AFAIS, I wasn't sure if we wanted to expose that.

Copy link
Member

Choose a reason for hiding this comment

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

Good point. Let's leave it like this, then.

@kzc
Copy link

kzc commented May 18, 2016

FWIW, dtruss on Mac showed that node 4.x and 5.x process.stdout._handle.fd was returning a closed fd in this case:

node -e 'require("fs").writeSync(process.stdout._handle.fd, "Hello.\n")'

@bnoordhuis
Copy link
Member

LGTM

On OSX it's possible that the fd is replaced, so use the proper libuv
API to get the correct fd.

PR-URL: nodejs#6753
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@saghul saghul closed this May 19, 2016
@saghul saghul deleted the fix-getfd branch May 19, 2016 08:55
@saghul saghul merged commit 4fe1d6e into nodejs:master May 19, 2016
@bnoordhuis
Copy link
Member

@saghul I didn't realize it at the time but we have similar logic in src/udp_wrap.cc.

@saghul
Copy link
Member Author

saghul commented May 20, 2016

Oh, me neither. I'll make a PR later today if nobody beats me to it.
On May 20, 2016 12:31, "Ben Noordhuis" notifications@github.com wrote:

@saghul https://github.com/saghul I didn't realize it at the time but
we have similar logic in src/udp_wrap.cc.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#6838 (comment)

saghul added a commit to saghul/node that referenced this pull request May 23, 2016
Refs: nodejs#6838
PR-URL: nodejs#6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@kzc kzc mentioned this pull request May 25, 2016
8 tasks
@Fishrock123
Copy link
Contributor

^ @thealphanerd

@MylesBorins MylesBorins self-assigned this May 26, 2016
@MylesBorins
Copy link
Contributor

@Fishrock123 patch applies cleanly to v4.x-staging will land after it has lived in a release for a week 😄

Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 30, 2016
Refs: nodejs#6838
PR-URL: nodejs#6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

@saghul is this at all specific to v1.9.0?

rvagg pushed a commit that referenced this pull request Jun 2, 2016
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
saghul added a commit to saghul/node that referenced this pull request Jul 11, 2016
Refs: nodejs#6838
PR-URL: nodejs#6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins removed their assignment Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants