win,pipe: fix race with concurrent readers#4470
Merged
vtjnash merged 3 commits intolibuv:v1.xfrom Aug 2, 2024
Merged
Conversation
We could also substantially improve performance now also, since the PeekFile call is unnecessary overhead with this change.
…ct results in uv__pipe_read_exactly due to missing IOCP argument
Member
Author
|
Okay, I think this is finished now. The good thing is that this also seems to roughly double throughput performance $ ./before/uv_run_benchmarks_a pipe_pump100_client
ok 1 - pipe_pump100_client
# pipe_pump100_server: 9.2 gbit/s
# pipe_pump100_client: 9.2 gbit/s
$ ./after/uv_run_benchmarks_a pipe_pump100_client
ok 1 - pipe_pump100_client
# pipe_pump100_server: 17.7 gbit/s
# pipe_pump100_client: 17.7 gbit/s |
bnoordhuis
approved these changes
Aug 1, 2024
Member
bnoordhuis
left a comment
There was a problem hiding this comment.
LGTM with an 85% confidence rate. :-)
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
vtjnash
added a commit
to vtjnash/libuv
that referenced
this pull request
Aug 19, 2024
In libuv#4470, I accidentally copied the bug from unix, where calling uv_stream_set_blocking can cause the whole process to hang on a read. However, unlike unix, where libuv attempts to set the O_NONBLOCK flag in uv_pipe_open (as long as the handle never gets passed to uv_spawn), the NT kernel is not capable of enabling OVERLAPPED operation later (but fortunately, it also cannot disable it later too). This implementation might be good to copy to unix (using FIONREAD) to address the same bug that happens there if the user has called uv_spawn or uv_stream_set_non_blocking on this handle in the past.
vtjnash
added a commit
that referenced
this pull request
Aug 22, 2024
In #4470, I accidentally copied the bug from unix, where calling uv_stream_set_blocking can cause the whole process to hang on a read. However, unlike unix, where libuv attempts to set the O_NONBLOCK flag in uv_pipe_open (as long as the handle never gets passed to uv_spawn), the NT kernel is not capable of enabling OVERLAPPED operation later (but fortunately, it also cannot disable it later too). This implementation might be good to copy to unix (using FIONREAD) to address the same bug that happens there if the user has called uv_spawn or uv_stream_set_non_blocking on this handle in the past.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a race condition if multiple threads are reading from the same NamedPipe, which could previously lead to a deadlock situation. We could also substantially improve performance now also, since the PeekFile call is unnecessary overhead with this change.
Related to #4467, though doesn't address any of the problems there. I believe that someone could now implement
uv__pipe_try_writeusing exactly this same code pattern however.The various
*= 2;are to prove that this works and fixes the bug, but should be removed before merging. A small bit of additional code cleanup may be possible as well now?