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

posix connect() blocks even when O_NONBLOCK is set. #2412

Closed
JonathanHenson opened this issue Aug 11, 2017 · 3 comments
Closed

posix connect() blocks even when O_NONBLOCK is set. #2412

JonathanHenson opened this issue Aug 11, 2017 · 3 comments

Comments

@JonathanHenson
Copy link

This bug-tracker is monitored by developers and other technical types. We like detail! So please use this form and tell us, concisely but precisely, what's up. Please fill out ALL THE FIELDS!

If you have a feature request, please post to the UserVoice. If you're reporting a BSOD, don't post here! Instead, e-mail "secure@microsoft.com", and if possible attach the minidump from "C:\Windows\minidump".

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.15063]

  • What you're doing and what's happening: (Copy&paste specific commands and their output, or include screen shots)
    I'm working on Async-IO network programming. While testing, I noticed that connect() always blocks, even when O_NONBLOCK is set. So I decided to put in a bad endpoint, to see if it would block even when the operation should take a long time. Instead, on WSL it hangs the application for 30 seconds or so.

int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
//this line will always block on WSL
int error_code = connect(socket->socket_handle, (struct sockaddr *)&addr_in, sizeof(addr_in));

  • What's wrong / what should be happening instead:

  • Strace of the failing command, if applicable: (If <cmd> is failing, then run `strace -o strace.txt -ff

On both my Ubuntu box and my Centos box, this happens:

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 10
fcntl(10, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK) = 0
write(1, "made connect call\n", 18made connect call
) = 18
connect(10, {sa_family=AF_INET, sin_port=htons(801), sin_addr=inet_addr("216.58.216.174")}, 16) = -1 EINPROGRESS (Operation now in progress)
write(1, "connect call finished with error"..., 41connect call finished with error code -1
) = 41

Returning EINPROGRESS immediately

On WSL, I get:

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 10
fcntl(10, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK) = 0
write(1, "made connect call\n", 18made connect call
) = 18
connect(10, {sa_family=AF_INET, sin_port=htons(801), sin_addr=inet_addr("216.58.216.174")}, 16) = -1 EAGAIN (Resource temporarily unavailable)
write(1, "connect call finished with error"..., 41connect call finished with error code -1
) = 41

After 30 seconds or so.

What should happen is it should return EINPROGRESS as the linux man says it should.

See our contributing instructions for assistance.

@benhillis
Copy link
Member

benhillis commented Aug 11, 2017

Support for non-blocking connect was added recently will be available in an Insider build soon.

@JonathanHenson
Copy link
Author

awesome, glad it's on your radar! And that it wasn't just a bug in my code.

@benhillis
Copy link
Member

Adding links to some duplicates: #903, #1391, #1584, #1585, #1829.

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

No branches or pull requests

3 participants