Repository navigation
Closed
Labels
Description
WSL never returns 0 for success if connect() is called multiple times on a non-blocking socket, it transitions straight from EINPROGRESS to EISCONN.
Build 10.0.16299
repro:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
int main() {
int fd = socket( AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0 );
if (fd < 0)
perror("socket: ");
struct sockaddr_in ip4addr;
ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons(80);
inet_pton(AF_INET, "74.125.69.99", &ip4addr.sin_addr);
for(;;) {
int res = connect(fd, (struct sockaddr*)&ip4addr, sizeof(ip4addr));
printf("called connect, res=%d ", res);
if(res < 0) {
printf(" errno=%d ", errno);
switch(errno) {
case EINPROGRESS:
printf(" in progress\n");
continue;
case EALREADY:
printf(" already in progress\n");
continue;
case EISCONN:
printf(" is connected\n");
goto done;
default:
printf(" something else, bailing out\n");
goto done;
}
} else {
printf("\n");
}
}
done:
return 0;
}
Linux
called connect, res=-1 errno=115 in progress
called connect, res=-1 errno=114 already in progress
called connect, res=-1 errno=114 already in progress
...
called connect, res=-1 errno=114 already in progress
called connect, res=-1 errno=114 already in progress
called connect, res=0
called connect, res=-1 errno=106 is connected
WSL
called connect, res=-1 errno=115 in progress
called connect, res=-1 errno=114 already in progress
called connect, res=-1 errno=114 already in progress
...
called connect, res=-1 errno=114 already in progress
called connect, res=-1 errno=114 already in progress
called connect, res=-1 errno=106 is connected
Possibly related to #2846
Reacted by therealkenc and ailin-nemui
Activity
mcgoo commentedon Feb 13, 2018
Also present in 10.0.17093.1000.
therealkenc commentedon Feb 13, 2018
I'd be surprised if it wasn't. Was
irssiwhat you were tracking, or did you just happen across that issue? Which is to say, if you have another breaking case, the better. Great post on the merits either way.mcgoo commentedon Feb 14, 2018
No, it's a binary vendor library. I found the
irssiissue by searching forWSLconnectEINPROGRESSI think.therealkenc commentedon Aug 1, 2020
Just did the exercise and the OP (thank you for the concise repro) still does not behave correctly (return
res=0) on WSL1 20180.Better in WSL2.