Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Use WSADuplicateSocket to duplicate socket handles on fork #1174

Open
G4Vi opened this issue May 7, 2024 · 1 comment
Open

[Windows] Use WSADuplicateSocket to duplicate socket handles on fork #1174

G4Vi opened this issue May 7, 2024 · 1 comment

Comments

@G4Vi
Copy link
Collaborator

G4Vi commented May 7, 2024

Due to Layered Service Providers(LSPs), the socket handles are not properly duplicated by calling CreateProcess with bInheritHandles=TRUE. The duplicated handles in the child processes work for some things, but not others. For example AcceptEx on a duplicated listen socket seems to work, but then setsockopt( sAcceptSocket, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char *)&sListenSocket, sizeof(sListenSocket) ); fails making it impossible to call getpeername or any other function not in the list in the AcceptEx remarks section: https://learn.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-acceptex#remarks

The problem with inherited sockets is discussed more here: https://stackoverflow.com/questions/11847793/are-tcp-socket-handles-inheritable

As we control the source for the parent and child process, it should be possible to use WSADuplicateSocket to properly pass a socket to a child process.

@G4Vi
Copy link
Collaborator Author

G4Vi commented Sep 2, 2024

This patch may be revertible if this is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant