Rethink the Accept() logic to differentiate between errors and cancellation#14156
Merged
Rethink the Accept() logic to differentiate between errors and cancellation#14156
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Accept() logic in WSL to differentiate between genuine errors and cancellation via exit events. The key change is renaming Accept to CancellableAccept and changing the return type to indicate whether the accept succeeded or was cancelled, allowing callers to avoid logging spurious errors during normal VM shutdown.
Changes:
- Introduced new relay infrastructure (
MultiHandleWait,OverlappedIOHandle,SingleAcceptHandle,EventHandle) to support cancellable I/O operations - Changed
Acceptfunctions toCancellableAcceptwith return typesbool(socket.cpp) andstd::optional<wil::unique_socket>(hvsocket.cpp) to distinguish cancellation from errors - Updated all call sites in wslrelay, localhost relay, and WslCoreVm to handle the new return semantics
- Added utility macros (
NON_COPYABLE,NON_MOVABLE,DEFAULT_MOVABLE) to defs.h - Changed timeout parameter type from
inttoDWORDfor consistency with Windows APIs
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/common/socket.hpp | Changed Accept to CancellableAccept returning bool, changed timeout from int to DWORD |
| src/windows/common/socket.cpp | Reimplemented CancellableAccept using new MultiHandleWait infrastructure to support cancellation |
| src/windows/common/hvsocket.hpp | Changed Accept to CancellableAccept returning std::optional<wil::unique_socket>, changed timeout from int to DWORD |
| src/windows/common/hvsocket.cpp | Updated to call CancellableAccept and return empty optional on cancellation |
| src/windows/common/relay.hpp | Added new relay infrastructure classes and utility macros for managing overlapped I/O and cancellation |
| src/windows/common/relay.cpp | Implemented MultiHandleWait, EventHandle, and SingleAcceptHandle for cancellable operations |
| src/windows/wslrelay/main.cpp | Updated to use CancellableAccept and return exit code 1 on cancellation |
| src/windows/wslrelay/localhost.cpp | Updated to use CancellableAccept and break loop on cancellation |
| src/windows/service/exe/WslCoreVm.cpp | Updated three call sites to handle optional return from CancellableAccept and break on cancellation |
| src/shared/inc/defs.h | Added NON_COPYABLE, NON_MOVABLE, and DEFAULT_MOVABLE utility macros |
benhillis
approved these changes
Feb 4, 2026
benhillis
approved these changes
Feb 4, 2026
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.
Summary of the Pull Request
This change reworks the Accept() logic to differentiate between unexpected errors and cancellation via the exit event. This allows the caller not to log and error when an accept is simply cancelled, which greatly removes the amount of errors that we log when the VM terminates normally
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed