-
Notifications
You must be signed in to change notification settings - Fork 653
windows: fix compatibility with cygwin pipes #1067
Conversation
Thank you for contributing this pull request! Here are a few pointers to make sure your submission will be considered for inclusion. The following commiters were not found in the CLA:
You can fix all these things without opening another issue. Please see CONTRIBUTING.md for more information |
…nnected. also, duplicate handles to ensure the original handle remains valid after uv_close (esp. important for stdio)
Everything after the : should go into a new line, because it is a small description of the headline. |
@txdv are you looking at my second referenced commit? It's not clear from GitHub's view, but it was in a working branch (before I cleaned up the commit description to keep Jenkins from complaining). |
/cc @piscisaureus |
bump |
Would this be fixing nodejs/node-v0.x-archive#6459 ? |
Looks like it would. Unfortunately this is way out of my Windows knowledge so we'd need some imput on it. @piscisaureus, @orangemocha does this look like a good approach? |
Hey @vtjnash, it's hard for me to review this code because I don't understand what the issues are with cygwin pipes and your code has no comments that explain it. Of course I can now bitch about how you're duplicating handles without ever closing them and code style etc. but before that I'd like to understand it better. Can you maybe explain the issue that this solves; if that's unpractical we can maybe make an appointment so I'll be on IRC (or some other medium) and we can chat about it. |
@@ -230,7 +230,7 @@ static int uv_set_pipe_handle(uv_loop_t* loop, | |||
NTSTATUS nt_status; | |||
IO_STATUS_BLOCK io_status; | |||
FILE_MODE_INFORMATION mode_info; | |||
DWORD mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT; | |||
DWORD mode = PIPE_READMODE_BYTE | PIPE_WAIT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PIPE_TYPE_BYTE
isn't a valid flag, although it didn't matter since it's value is 0.
A portion of this patch was independently executed in ba47e68 I've reworked (shortened) this to incorporate those changes, and join IRC when I have availability (usually late in the evenings). It looks like I had some rebase issues when I copied this from the Julia fork (we have other changes there that fix the read/write flags of pipes on other platforms and the behavior of uv_spawn for all platforms per #451. I removed the changes -- such as duplicating handles from the host process -- that aren't directly relevant) |
@@ -246,11 +246,9 @@ static int uv_set_pipe_handle(uv_loop_t* loop, | |||
if (!GetNamedPipeHandleState(pipeHandle, ¤t_mode, NULL, NULL, | |||
NULL, NULL, 0)) { | |||
return -1; | |||
} else if (current_mode != mode) { | |||
} else if (current_mode&PIPE_NOWAIT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously, this verified that the pipe is in PIPE_READMODE_BYTE
, but cygwin puts it in PIPE_READMODE_MESSAGE
(IIRC, this was changed because it gives better behavior when there are multiple writers) and doesn't give us the permissions to edit the mode. however this should be fine, since we can always just read bytes at a time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: spaces around '&'
This makes libuv more tolerant of the properties of the pipes that it can use without any issue. this is necessary because Cygwin (and hence Mintty) opens STDIN without FILE_WRITE_ATTRIBUTES.
BUMP |
Bump^2 ;). If there's anything we can clarify, please let us know. |
The new cleaned-up code LGTM. It just takes care of settig the readable/writable flags approriately. Can you do a quick lookover, @piscisaureus? PS: There are a few style issues (mostly space between operators), we can fix those during merge. |
Ok, I understand what you're trying to do now and it seems good. I would really like it if you could add a comment to the code stating that cygwin opens the pipe in message mode but we can support that just fine. That way the knowledge in our heads doesn't get lost - you've probably already noticed that I am not around a lot any more, but there will be maintainers in the future and it'd be great if they don't have to reverse engineer your intent here. @saghul is right, there are a few style nits but nothing that takes more than 5 minutes to fix. so lgtm |
@@ -1771,8 +1769,33 @@ static void eof_timer_close_cb(uv_handle_t* handle) { | |||
|
|||
|
|||
int uv_pipe_open(uv_pipe_t* pipe, uv_file file) { | |||
HANDLE os_handle = uv__get_osfhandle(file); | |||
DWORD duplex_flags = UV_HANDLE_READABLE | UV_HANDLE_WRITABLE; | |||
HANDLE os_handle = (HANDLE)uv__get_osfhandle(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded cast?
Thanks @piscisaureus! I made some comments about the style issues, @Keno @vtjnash please fix those and add a explanatory comment and this is good to go! |
Made the changes myself and landed it in ebafb90, thanks! |
This makes libuv more tolerant of the properties of the pipes
that it can use. this is necessary because Cygwin (and hence Mintty)
opens
STDIN
withoutFILE_WRITE_ATTRIBUTES
. Also, this always duplicatehandles from external sources, to ensure the original handle can remain
valid after uv_close (this can be important for stdio since the system
libraries do not expect it to be closed by the user).