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

non blocking connect() never succeeds #2949

Closed
mcgoo opened this issue Feb 13, 2018 · 4 comments
Closed

non blocking connect() never succeeds #2949

mcgoo opened this issue Feb 13, 2018 · 4 comments

Comments

@mcgoo
Copy link

mcgoo commented Feb 13, 2018

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

@mcgoo
Copy link
Author

mcgoo commented Feb 13, 2018

Also present in 10.0.17093.1000.

@therealkenc
Copy link
Collaborator

therealkenc commented Feb 13, 2018

Possibly related to #2846

I'd be surprised if it wasn't. Was irssi what 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
Copy link
Author

mcgoo commented Feb 14, 2018

No, it's a binary vendor library. I found the irssi issue by searching for WSL connect EINPROGRESS I think.

@therealkenc
Copy link
Collaborator

Just did the exercise and the OP (thank you for the concise repro) still does not behave correctly (return res=0) on WSL1 20180.

image

Better in WSL2.

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

2 participants