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
jstarks opened this issue
May 30, 2025
· 2 comments
· May be fixed by #141809
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.
// only perform cleanup if network functionality was actually initialized
ifletSome(cleanup) = WSA_CLEANUP.get(){
unsafe{
cleanup();
}
}
}
This is an unnecessary expense--the process is going away, so there's nothing WSACleanup can do that won't also be done by the kernel when the process terminates. In a short-lived process, the call takes about 60us if you've only used TCP. If you also have used AF_UNIX and AF_HYPERV, for example, it takes about 400us--this is because it has to unload some DLLs that were dynamically loaded. If some of the data is cold, it has the potential to take much longer. None of this is necessary to "cleanly" terminate a process.
Now, arguably, you might want to call WSACleanup on DLL unload, to ensure you've cleaned everything up. But Rust does not do this today, AFAICT, just as it doesn't drop statics, either on DLL unload or on clean exit from main. So this WSACleanup behavior seems inconsistent.
Seems reasonable to me. I looked back at the history here and it seems it was added in the initial implementation ~11 years ago and more or less kept ever since.
I'd add that std doesn't really support unloading itself. Not that it isn't possible but we don't have any test coverage for that and doing it soundly is very much on the user, as far as I'm aware.
The only potential issue I'm hearing is that it may be flagged by some tools as a bug.
Noratrieb
added
O-windows
Operating system: Windows
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
A-io
Area: `std::io`, `std::fs`, `std::net` and `std::path`
and removed
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Jun 1, 2025
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.
On Windows,
std
callsWSACleanup
at exit if it calledWSAStartup
, to uninitialize Windows sockets:rust/library/std/src/sys/net/connection/socket/windows.rs
Lines 137 to 144 in 15825b7
This is an unnecessary expense--the process is going away, so there's nothing
WSACleanup
can do that won't also be done by the kernel when the process terminates. In a short-lived process, the call takes about 60us if you've only used TCP. If you also have used AF_UNIX and AF_HYPERV, for example, it takes about 400us--this is because it has to unload some DLLs that were dynamically loaded. If some of the data is cold, it has the potential to take much longer. None of this is necessary to "cleanly" terminate a process.Now, arguably, you might want to call
WSACleanup
on DLL unload, to ensure you've cleaned everything up. But Rust does not do this today, AFAICT, just as it doesn't drop statics, either on DLL unload or on clean exit frommain
. So thisWSACleanup
behavior seems inconsistent.@ChrisDenton wdyt?
The text was updated successfully, but these errors were encountered: