-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Cloned sockets are inherited by child processes on windows #70719
Copy link
Copy link
Open
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`A-processArea: `std::process` and `std::env`Area: `std::process` and `std::env`C-bugCategory: This is a bug.Category: This is a bug.O-windowsOperating system: WindowsOperating system: WindowsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`A-processArea: `std::process` and `std::env`Area: `std::process` and `std::env`C-bugCategory: This is a bug.Category: This is a bug.O-windowsOperating system: WindowsOperating system: WindowsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Given this test code running on Windows 10 compiled with rustc 1.41.0:
I would expect UDP port 9999 to no longer be listening after the code terminates and I would expect both
socket1andsocket2to reportfalseon the state of theirHANDLE_FLAG_INHERIT.Instead port 9999 remains in a listening state until I close the spawned child process
notepadandsocket2shows that itsHANDLE_FLAG_INHERITis set.This appears to have been introduced in rust 1.38.0 via PR #60260 which now sets the
WSA_FLAG_NO_HANDLE_INHERITinWSASocketWinstead of explicitly clearing theHANDLE_FLAG_INHERITwithSetHandleInformation. Just to confirm, I have compiled this againstnightly-2019-07-26-x86_64-pc-windows-msvc(before PR) andnightly-2019-07-27-x86_64-pc-windows-msvc(after PR) and this code behaves as expected before the PR.On the surface that PR looks solid and I would totally expect it to work. However it seems (surprisingly) that setting the
WSA_FLAG_NO_HANDLE_INHERITflag on a duplicated socket is not effective. I have googled until I could google no longer and alas have found no mention of this behavior.As a workaround, doing something like:
fixes my use case.
Perhaps the correct fix is for
duplicateto callset_no_inheritunless it is a UWP app. However I would love it if someone had deeper knowledge as to why this behavior is as it is.