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

TcpListener::bind broken under Windows 7 #26543

Closed
mohtar opened this issue Jun 24, 2015 · 2 comments
Closed

TcpListener::bind broken under Windows 7 #26543

mohtar opened this issue Jun 24, 2015 · 2 comments
Labels
O-windows Operating system: Windows

Comments

@mohtar
Copy link

mohtar commented Jun 24, 2015

Creating a TCP listener socket will result in error under Windows 7. Minimal test case:

fn main() {
    use std::net::TcpListener;
    let listener = TcpListener::bind("127.0.0.1:8000").unwrap();
}

This will produce an error with code 10041 (WSAEPROTOTYPE).

This was tested on stable Rust (1.0.0).

After a bit digging, turns out this particular piece of code might be the cause of the breakage. According to the Winsock docs, The WSA_FLAG_NO_HANDLE_INHERIT flag is supported on at least Windows 7 SP1, so running on vanilla Windows 7 would not work and would apparently break your program.

@sfackler sfackler added O-windows Operating system: Windows A-libs labels Jun 24, 2015
@sfackler
Copy link
Member

cc @retep998 @alexcrichton

@nagisa
Copy link
Member

nagisa commented Jun 25, 2015

Might be similar to #26518.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 1, 2015
This was added after Windows 7 SP1, so it's not always available. Instead use
the `SetHandleInformation` function to flag a socket as not inheritable. This is
not atomic with respect to creating new processes, but it mirrors what Unix does
with respect to possibly using the atomic option in the future.

Closes rust-lang#26543
bors added a commit that referenced this issue Jul 1, 2015
This was added after Windows 7 SP1, so it's not always available. Instead use
the `SetHandleInformation` function to flag a socket as not inheritable. This is
not atomic with respect to creating new processes, but it mirrors what Unix does
with respect to possibly using the atomic option in the future.

Closes #26543
bors added a commit that referenced this issue Dec 6, 2019
std:win: avoid WSA_FLAG_NO_INHERIT flag and don't use SetHandleInformation on UWP

This flag is not supported on Windows 7 before SP1, and on windows server 2008 SP2. This breaks Socket creation & duplication.
This was fixed in a previous PR. cc #26658

This PR: cc #60260 reuses this flag to support UWP, and makes an attempt to handle the potential error.
This version still fails to create a socket, as the error returned by WSA on this case is WSAEINVAL (invalid argument). and not WSAEPROTOTYPE.

MSDN page for WSASocketW (that states the platform support for WSA_FLAG_NO_HANDLE_INHERIT): https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw

CC #26543
CC #26518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

3 participants