Support full duplex traffic and half close socket in NAT localhost relay - #41458
Open
Feng Wang (chemwolf6922) wants to merge 3 commits into
Open
Support full duplex traffic and half close socket in NAT localhost relay#41458Feng Wang (chemwolf6922) wants to merge 3 commits into
Feng Wang (chemwolf6922) wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
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, introducingHalfCloseRelayHandleto propagate half-close (shutdown(SD_SEND)) without terminating the opposite direction. - Rewrites the Linux localhost relay into a non-blocking, event-driven
epollloop 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. |
| src/windows/common/relay.cpp | Replaces legacy WaitForMultipleObjects relay loop with MultiHandleWait + relay handle abstractions. |
| src/windows/common/HandleIO.h | Extends ReadHandle to accept a buffer size; adds HalfCloseRelayHandle declaration. |
| src/windows/common/HandleIO.cpp | Implements buffer-sized ReadHandle construction and HalfCloseRelayHandle shutdown behavior. |
| src/linux/init/localhost.cpp | Replaces blocking/threaded relay with per-connection state machine driven by epoll on non-blocking sockets. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
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 returnEINTRwhen 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. TreatEINTRlikeEINPROGRESSand let epoll complete the connection instead.
const int result = connect(m_tcpSocket.get(), socketAddress, socketAddressSize);
if (result < 0 && errno != EINPROGRESS)
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 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