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

Update Cygwin ICMP service thread for asynchronous pipes #495

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

matt-kimball
Copy link
Contributor

Recent versions of Cygwin implement pipe() using Windows' named pipes, and put the read end of the pipe in FILE_PIPE_COMPLETE_OPERATION mode, which doesn't allow overlapped I/O operations.

For the relevant commit in the Cygwin repository, see 9e4d308cd592fe383dec58ea6523c1b436888ef8

Happily, this mode is approximately equivalent to Unix's non-blocking read mode, so we can avoid overlapped I/O entirely, and instead wait on the Windows handle for the read end of the pipe when we need an alertable wait to receive ICMP probe completions.

Thanks to Adam Schultz for research into this issue and a first attempt at a fix.

This fixes issue #465

@matt-kimball
Copy link
Contributor Author

Actually, upon further investigation, WaitForSingleObject on the named pipe handle doesn't accomplish what I thought it would. Do not merge this PR yet - I will update with a better solution.

Recent versions of Cygwin implement pipe() using Windows' named
pipes, and put the read end of the pipe in FILE_PIPE_COMPLETE_OPERATION
mode, which doesn't allow overlapped I/O operations.

For the relevant commit in the Cygwin repository, see
9e4d308cd592fe383dec58ea6523c1b436888ef8

The solution here is to maintain a Windows event object which is
set only when any ICMP requests are pending.  We can do an alertable
wait on that event object, which will allow us to complete ICMP
requests.

Thanks to Adam Schultz for research into this issue and a first
attempt at a fix.
@matt-kimball
Copy link
Contributor Author

PR updated. Unfortunately, the solution was slightly more complicated and uses some new Windows synchronization primitives, but now actually works to block in the alertable wait. I have tested this with newer versions of Cygwin, and it works as expected, but I also believe it will work for the older versions of Cygwin, and is less fragile since it no longer retrieves the Windows HANDLE of the pipe created by Cygwin and therefore doesn't depend on how Cygwin implements it.

@rewolff rewolff merged commit e137a71 into traviscross:master Oct 24, 2023
2 checks passed
@matt-kimball matt-kimball deleted the cygwin-async-pipe branch October 24, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants