Skip to content

Use PIPE_NOWAIT on Windows to avoid blocking on writes #781

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

Merged
merged 3 commits into from
Mar 8, 2023
Merged

Use PIPE_NOWAIT on Windows to avoid blocking on writes #781

merged 3 commits into from
Mar 8, 2023

Conversation

tristanlabelle
Copy link
Contributor

@tristanlabelle tristanlabelle commented Mar 3, 2023

libdispatch depends on non-blocking writes to retry later. For pipes on Windows, we achieved this using NtQueryInformationFile to get the WriteQuotaAvailable for the pipe, but this function returns 0 when there is a blocking read on the receiver side (this appears to be an OS bug), which causes us to never proceed to the write.

This change rather sets PIPE_NOWAIT on the pipe's write handle, similar to what is done on other platforms. This call will fail if the pipe handle does not have FILE_WRITE_ATTRIBUTES set, which is not a problem with the typical case of using a Foundation.Pipe. If we cannot set PIPE_NOWAIT, we will proceed with blocking writes, which in some circumstances could lead to hangs.

This resolves an issue with SourceKit-LSP on Windows where tests and real-life scenarios would hang because a pipe could never be written to.

@tristanlabelle tristanlabelle marked this pull request as ready for review March 6, 2023 20:51
@compnerd
Copy link
Member

compnerd commented Mar 6, 2023

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Mar 7, 2023

@swift-ci please test Windows platform

1 similar comment
@compnerd
Copy link
Member

compnerd commented Mar 7, 2023

@swift-ci please test Windows platform

@compnerd
Copy link
Member

compnerd commented Mar 7, 2023

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Mar 8, 2023

@swift-ci please test Windows platform

@compnerd
Copy link
Member

compnerd commented Mar 8, 2023

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Mar 8, 2023

@swift-ci please test Windows platform

@tristanlabelle
Copy link
Contributor Author

I ran tests locally. 22/22 passed.

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