Repository navigation
Conversation
… reads and writes on Windows side
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors the localhost relay implementation to use non-blocking, back-pressure-aware I/O on Linux and IOCP-based fully asynchronous I/O on Windows, improving full-duplex throughput and correct half-close behavior.
Changes:
- Windows: replaced wait/event-based overlapped I/O with IOCP dispatch and per-direction read/write state machines.
- Linux: switched sockets to non-blocking mode and implemented a poll-driven relay with per-direction buffering and compaction.
- Added per-direction half-close handling so each direction can complete independently.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/windows/common/relay.cpp | Reworks BidirectionalRelay to use IOCP with per-direction async read/write contexts and completion processing. |
| src/linux/init/localhost.cpp | Implements a non-blocking poll() relay loop with per-direction buffers, back-pressure, and half-close support. |
|
“Thanks for the notification. Update received.”
获取 Outlook for iOS<https://aka.ms/o0ukef>
________________________________
发件人: wangxin12 ***@***.***>
发送时间: Tuesday, April 14, 2026 5:43:42 AM
收件人: microsoft/WSL ***@***.***>
抄送: Subscribed ***@***.***>
主题: Re: [microsoft/WSL] Localhost Relay: non-blocking IO on Linux side, IOCP with fully async reads and writes on Windows side (PR #40171)
@wangxin12 commented on this pull request.
________________________________
In src/linux/init/localhost.cpp<#40171 (comment)>:
+ if (pfds[j].events & POLLOUT)
{
- bytesRead = UtilReadBuffer(pollDescriptors[Index].fd, buffer);
- if (bytesRead == 0)
+ // can't write to dstFd any more
+ if (pfds[j].revents & (POLLERR | POLLHUP))
{
- pollDescriptors[Index].fd = -1;
- shutdown(outFd[Index], SHUT_WR);
+ d.done = true;
+ continue;
}
- else if (bytesRead < 0)
+
+ if (!(pfds[j].revents & POLLOUT))
{
- return;
+ continue;
+ }
Both fds are owned by unique_fd and are never closed during the relay loop, so POLLNVAL cannot occur.
―
Reply to this email directly, view it on GitHub<#40171 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B677FUKLYOJS6P74H5GV4N34VVNQZAVCNFSM6AAAAACXXZYSQCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DCMBSGEYTOMJXGM>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
|
guanwenbin123 Hi, could you please configure your auto reply so it does not create a message for every wsl update? Thanks. |
| rightOverlapped.hEvent = rightOverlappedEvent.get(); | ||
| LARGE_INTEGER rightOffset{}; | ||
| // Create a completion port and associate both handles. | ||
| wil::unique_handle iocp(CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 1)); |
There was a problem hiding this comment.
On the windows I think it would be nice to reuse MultHandleWait to do all of the IO scheduling (especially once https://github.com/microsoft/WSL/pull/40042/changes is merged)
We could either cherry-pick the changes from features/wsl-for-apps, or we could wait until that feature branch is merged into master, which should happen in the coming month
There was a problem hiding this comment.
Good to know. Let's wait for https://github.com/microsoft/WSL/pull/40042/changes to be merged, then I can refactor changes on Windows side
There was a problem hiding this comment.
Hi Blue (@OneBlue) Ben Hillis (@benhillis) , I cherry pick Ben's commit and make change on top of it (the PR seems to be still in working and have not updated for several weeks). Could you help review this when you get a chance?
I'd like to get this fix into the next 2.7.x release train if possible. Let me know your thought on this. Thanks!
The previous fix unconditionally called GetOverlappedResult(bWait=TRUE), which hangs in IOCP mode because Overlapped.hEvent is nullptr and cancellation completions go to the IOCP queue, not the file handle. Fix: when RegisteredWithIocp, set a temporary event in the OVERLAPPED before calling CancelIoEx so GetOverlappedResult can wait on it. This ensures the kernel is done with the OVERLAPPED before the destructor frees it, without hanging. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
|
Hi Blue (@OneBlue), I updated this PR with the latest |
Summary of the Pull Request
This PR improves the localhost relay performance and reliability on both Linux and Windows, and migrates the Windows
BidirectionalRelayto reuse the existingMultiHandleWait+RelayHandleinfrastructure.Linux
UtilRelayhelper (util.cpp) that usespoll()with non-blocking fds, per-direction buffering, back-pressure via available buffer space.localhost.cpp) now callsUtilRelayinstead of the old blocking relay, with caller-specified buffer sizes.Windows
HalfCloseRelayHandlefor socket specifically, supports half-close (shutdown(SD_SEND)) on EOF/error.BidirectionalRelaywithMultiHandleWait+ twoRelayHandle<>instances, for consistency with other relay callers.BufferSizethroughReadHandle→RelayHandle→BidirectionalRelayto preserve caller-specified buffer sizes (128KB for localhost relay vs 4KB default).Testing
Without the change, the test tool hangs.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed