Set SO_UPDATE_ACCEPT_CONTEXT on sockets accepted via AcceptEx in PortRelay#40505
Set SO_UPDATE_ACCEPT_CONTEXT on sockets accepted via AcceptEx in PortRelay#40505wangxin12 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Windows port relay implementations to call setsockopt(..., SO_UPDATE_ACCEPT_CONTEXT, ...) on sockets accepted via AcceptEx, ensuring the accepted socket is fully “connected” from Winsock’s perspective (enabling getpeername/getsockname/shutdown and related socket options to work correctly).
Changes:
- Set
SO_UPDATE_ACCEPT_CONTEXTafterAcceptExcompletion in thewslrelaylocalhost port relay (both async-completion and synchronous-completion paths). - Set
SO_UPDATE_ACCEPT_CONTEXTafterAcceptExcompletion in thewslcsessionPortRelayAcceptHandleaccept path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/windows/wslrelay/localhost.cpp | Updates the PortRelay accept flow to set SO_UPDATE_ACCEPT_CONTEXT on the accepted socket before relaying. |
| src/windows/wslcsession/PortRelayHandle.cpp | Updates PortRelayAcceptHandle::Collect() to set SO_UPDATE_ACCEPT_CONTEXT prior to launching the relay thread. |
|
Can you add a regression test please? |
Hi @benhillis , I looked into this and ran into a few obstacles that make a meaningful regression test hard. Wanted to walk through them and get your input on the best path forward.
|
| } | ||
|
|
||
| // Set the accept context to mark the socket as connected. | ||
| const SOCKET listenSocket = ListenSocket.get(); |
There was a problem hiding this comment.
nit: We could we move this to a shared helper in socket.hpp ? This is done in multiple places
Summary of the Pull Request
After
AcceptExcompletes, setSO_UPDATE_ACCEPT_CONTEXTto mark the socket as connected. Without this,getpeername/getsockname/shutdownand a number ofsetsockopt/getsockoptoptions fail on the accepted socket.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed