You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support full duplex traffic and half close socket in NAT localhost relay - Windows side - #41458
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves the NAT localhost relay implementation to correctly support full-duplex traffic and TCP half-close semantics, addressing hangs and premature connection teardown in bidirectional protocols.
Changes:
Refactors the Windows bidirectional relay to use MultiHandleWait, introducing HalfCloseRelayHandle to propagate half-close (shutdown(SD_SEND)) without terminating the opposite direction.
Rewrites the Linux localhost relay into a non-blocking, event-driven epoll loop to support full duplex and avoid per-connection threads.
Adds Windows unit/integration tests covering half-close and full-duplex behavior through the localhost relay.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File
Description
test/windows/UnitTests.cpp
Adds a unit test validating relay continues after half-close.
test/windows/NetworkTests.cpp
Adds WSL2 NAT localhost relay tests for half-close and full-duplex behavior; extends socat helper.
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/linux/init/localhost.cpp:521
connect() can return EINTR when a signal interrupts the attempt; for this case Linux leaves the connection attempt in progress, but this branch currently tears down the relay connection. The previous blocking implementation retried interrupted connects, and the new accept/read/write paths also handle interruptions. Treat EINTR like EINPROGRESS and let epoll complete the connection instead.
const int result = connect(m_tcpSocket.get(), socketAddress, socketAddressSize);
if (result < 0 && errno != EINPROGRESS)
Handle EINTR and EALREADY during nonblocking connect
src/linux/init/localhost.cpp:522
The old blocking connect used TEMP_FAILURE_RETRY, but this nonblocking call now treats EINTR (and the EALREADY that can result when an interrupted connect is retried) as a terminal connection failure. A signal during setup will therefore drop an otherwise viable relay connection instead of waiting for it to complete; retry the call on EINTR and accept EALREADY as an in-progress state.
Feng Wang (chemwolf6922)
changed the title
Support full duplex traffic and half close socket in NAT localhost relay
Support full duplex traffic and half close socket in NAT localhost relay - Windows side
Nov 9, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Test teardown can close relay sockets while the worker still uses them, and regression coverage does not exercise simultaneous bidirectional writes under back-pressure.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Failure-path cleanup closes relay sockets before the worker joins, risking races with pending I/O, and the tests do not verify reverse-traffic progress under write backpressure.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Test cleanup closes relay sockets before the worker finishes, risking outstanding I/O accessing destroyed buffers, and regression coverage omits full-duplex traffic under blocked-write back-pressure.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Completion and cancellation behavior still needs Windows runtime validation for TCP-to-Hyper-V and mixed socket/named-pipe KD relays, as the added tests cover only TCP loopback sockets.
Hi Tuna Birgün (@tunabirgun) . Thanks for the interest in this PR. However, please control the bot generated comments. It's disrupting the normal review message flow. I'll do a cleanup pass on those messages.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The asynchronous I/O and teardown changes affect TCP↔HvSocket NAT forwarding and socket↔pipe KD relaying, but tests cover only TCP↔TCP, leaving the production endpoint combinations unvalidated on Windows.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Windows runtime validation is needed for TCP↔Hyper-V half-close and KD socket↔named-pipe cancellation behavior, which the added loopback TCP tests do not cover.
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
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 is a continuation of wangxin12's work in #40171.
The original localhost relay, on both sides, would:
This PR makes the Windows side changes to support full duplex traffic and half close socket in NAT localhost relay:
MultiHandleWaitwith a new half close capable relay handle.The Linux changes will be in a separate PR.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Add tests:
UnitTests::UnitTests::BidirectionalRelayContinuesAfterHalfClose
UnitTests::UnitTests::BidirectionalRelayFullDuplexUnderBackpressure