Skip to content

Use RegisterWaitForSingleObject() in MultiHandleIOWait#40658

Merged
OneBlue merged 6 commits into
masterfrom
user/oneblue/io-refactor-4
May 28, 2026
Merged

Use RegisterWaitForSingleObject() in MultiHandleIOWait#40658
OneBlue merged 6 commits into
masterfrom
user/oneblue/io-refactor-4

Conversation

@OneBlue
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue commented May 28, 2026

Summary of the Pull Request

This change switches the IO scheduling logic to use RegisterWaitForSingleObject() instead of WaitForMultipleObject(), which allows us to wait for more than 64 handles at the same time.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

I also experimented with IO completion ports, but the change became too complex (see #40569).

This solution is self contained and works well with our current design

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 28, 2026 00:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates wsl::windows::common::io::MultiHandleWait to use RegisterWaitForSingleObject() callbacks instead of WaitForMultipleObjects(), removing the 64-handle waiting limitation and validating the behavior with new unit/e2e tests.

Changes:

  • Reworked MultiHandleWait::Run() to register per-handle waits and use a shared notification event when any handle signals.
  • Added a unit test that waits on 100 events to validate behavior above MAXIMUM_WAIT_OBJECTS.
  • Added an end-to-end WSLC test that starts 100 concurrent docker logs -f followers to exercise the new wait path.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/windows/common/HandleIO.h Refactors MultiHandleWait storage to per-handle Entry objects and introduces signaling queue/event members.
src/windows/common/HandleIO.cpp Implements the new wait strategy using RegisterWaitForSingleObject() and a registered-wait RAII wrapper.
test/windows/UnitTests.cpp Adds coverage ensuring MultiHandleWait can process >64 handles in both pre-signaled and live-signaled scenarios.
test/windows/WSLCTests.cpp Adds a stress-style test for many concurrent log followers to validate real-world usage beyond 64 waits.

Comment on lines +925 to +935
MultiHandleWait& MultiHandleWait::operator=(MultiHandleWait&& other) noexcept
{
if (this != &other)
{
m_handles = std::move(other.m_handles);
m_handleSignaledEvent = std::move(other.m_handleSignaledEvent);
m_cancel = other.m_cancel;

// N.B. moving a MultiHandleWait() while running is not supported
WI_ASSERT(m_signaledHandles.empty());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels like it is still an issue with an assert. Run should either permanently make the object unmovable or mark it unmovable until Run returns.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I considered doing something like this, but it felt overkill to add synchronization logic for this, since this would only be an issue if the object was moved while another thread is running it, which would be undefined behavior either way.

Also note that the diff of this comment is outdated. The latest iteration updates the self field when moved

Comment thread src/windows/common/HandleIO.cpp
Comment thread src/windows/common/HandleIO.h Outdated
Comment thread test/windows/WSLCTests.cpp
@OneBlue OneBlue marked this pull request as ready for review May 28, 2026 01:29
@OneBlue OneBlue requested a review from a team as a code owner May 28, 2026 01:29
Copilot AI review requested due to automatic review settings May 28, 2026 01:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/windows/common/HandleIO.h Outdated
benhillis
benhillis previously approved these changes May 28, 2026
Copy link
Copy Markdown
Member

@benhillis benhillis left a comment

Choose a reason for hiding this comment

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

This looks good, I think just that one copilot comment about the move contrustor.

@OneBlue OneBlue merged commit 0b402cd into master May 28, 2026
11 checks passed
@OneBlue OneBlue deleted the user/oneblue/io-refactor-4 branch May 28, 2026 19:48
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.

4 participants