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
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.
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 these changes to support full duplex traffic and half close socket in NAT localhost relay:
MultiHandleWaitwith a new half close capable relay handle.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Add tests:
NetworkTests::NetworkTests::NatLocalhostRelayHalfClose
NetworkTests::NetworkTests::NatLocalhostRelayFullDuplex
UnitTests::UnitTests::BidirectionalRelayContinuesAfterHalfClose