Skip to content

Rethink the Accept() logic to differentiate between errors and cancellation#14156

Merged
OneBlue merged 4 commits intomasterfrom
user/oneblue/accept-2
Feb 4, 2026
Merged

Rethink the Accept() logic to differentiate between errors and cancellation#14156
OneBlue merged 4 commits intomasterfrom
user/oneblue/accept-2

Conversation

@OneBlue
Copy link
Collaborator

@OneBlue OneBlue commented Feb 4, 2026

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

  • 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

Validation Steps Performed

Copy link
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 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 Accept functions to CancellableAccept with return types bool (socket.cpp) and std::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 int to DWORD for 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

@OneBlue OneBlue merged commit 1897d05 into master Feb 4, 2026
6 checks 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.

3 participants