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

socketpair() syscall ignores non-blocking request (SOCK_NONBLOCK, O_NONBLOCK) #3100

Closed
christianparpart opened this issue Apr 13, 2018 · 6 comments

Comments

@christianparpart
Copy link

christianparpart commented Apr 13, 2018

Hi,

(windows version: 10.0.17133.73)

I found out that the syscall socketpair is litereally ignoring the SOCK_NONBLOCK argument.
Also is fcntl's attempt to make socketpair's sockets non-blocking ignored.

Here's a minimal example program that proofs both cases. On original Linux it immediately quits as expected with the appropriate error message (EAGAIN), but on WSL/Linux it freezes after having filled one end with 163840 bytes.

#include <sys/socket.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int reportError(const char* syscall, int ec) {
  printf("%s: %s\n", syscall, strerror(ec));
  return 1;
}

int main(int argc, const char* argv[]) {
  int sv[2];
  int typeMask = 0;
  int flags = 0;

  if (argc == 2 && strcmp(argv[1], "-f") == 0) {
    flags |= O_NONBLOCK;
  } else {
    typeMask |= SOCK_NONBLOCK;
  }

  if (socketpair(PF_LOCAL, SOCK_STREAM | typeMask, 0, sv) < 0)
    return reportError("socketpair", errno);

  if (flags) {
    if (fcntl(sv[0], F_SETFL, flags) < 0)
      return reportError("fcntl", errno);
    if (fcntl(sv[1], F_SETFL, flags) < 0)
      return reportError("fcntl", errno);
  }

  static const char buf[4096] = {0};
  for (;;) {
    int rv = write(sv[0], buf, sizeof(buf));
    if (rv < 0) {
      reportError("write", errno);
      break;
    }
  }
  close(sv[0]);
  close(sv[1]);
  return 0;
}
@Biswa96
Copy link

Biswa96 commented Apr 13, 2018

Mention Windows build version.

@christianparpart
Copy link
Author

@Biswa96 added. thx!

@therealkenc
Copy link
Collaborator

Rare; +1 (I was loosing faith). Not even sure it is a dupe (too hard to search).

@christianparpart
Copy link
Author

christianparpart commented Apr 17, 2018

That is why I am dog-clear in subject and description, including example-code to reproduce. No other ticket came close to it, that's why I created a dedicated one.

@therealkenc
Copy link
Collaborator

It's #2949, I think (right?). Don't quibble on the flags. Won't dupe ya.

@Brian-Perkins
Copy link

This should be fixed in build 17666.

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

No branches or pull requests

4 participants