WSL: Node Pipe cannot connect

With the newest build (14965), I was hopeful that my issues with using node on WSL would have been cleared up. In this case, the error is being throw deep in the ember-cli build process, but it happens elsewhere as well.

I believe the issue to be twofold: one issue in the error lookup from libuv, the other with the pipe connector itself.

The error that is thrown:

util.js:1018
  var errname = uv.errname(err);
                   ^

Error: err >= 0
    at Object.exports._errnoException (util.js:1018:20)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)

My case is a full ember-cli-rails project that takes a bit of setup, but this seems to be throwing the same error: https://github.com/nodejs/node/issues/9534

const {spawn} = require('child_process');

const sockets = spawn('go', ['run', 'sockets.go']);

I suspect that the crash is coming from an issue with libuv error lookup as the message err >= 0 is not very helpful. I am not certain what the original exception is because it doesn’t get that far. The pipe code, so far as I can tell is here: https://github.com/nodejs/node/blob/master/src/pipe_wrap.cc

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 24 (8 by maintainers)

Most upvoted comments

Just to be clear, both SCM_RIGHTS and SCM_CREDENTIALS are currently supported, but not at the same time. Also the current implementation of SCM_RIGHTS does not support passing more than one FD at a time. Very limited. I am working to remove all these limitations.

getsockopt(..., SOL_SOCKET, SO_ERROR, ...) still returns EINVAL as of 14965. Test case below is clean on Real Linux™.

/** so-error.cc **/

#include <sys/types.h> 
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, const char* argv[]) {
  const char* path = "./sock";
  unlink(path);
  struct sockaddr_un addr = {};
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, path);

  int lsd = socket(PF_LOCAL, SOCK_STREAM, 0);
  bind(lsd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr));
  listen(lsd, 10);

  int cfd = socket(PF_LOCAL, SOCK_STREAM, 0);
  connect(cfd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr));

  int err;
  socklen_t optlen = sizeof(int);
  if (getsockopt(cfd, SOL_SOCKET, SO_ERROR, &err, &optlen) < 0) {
    perror("getsockopt: ");
    _exit(-1);
  }

  return 0;
}

strace:

socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
bind(3, {sa_family=AF_LOCAL, sun_path="./sock"}, 110) = 0
listen(3, 10)                           = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 4
connect(4, {sa_family=AF_LOCAL, sun_path="./sock"}, 110) = 0
getsockopt(4, SOL_SOCKET, SO_ERROR, 0x7ffff1a0dab8, 0x7ffff1a0dabc) = 
    -1 EINVAL (Invalid argument)

Good call @fpqc found the call that threw the error (with gettime and futex calls removed):

[pid 19771] connect(12, {sa_family=AF_LOCAL, sun_path="/usr/local/var/run/watchman/kayakyakr-state/sock"}, 110) = 0
[pid 19771] socket(PF_LOCAL, SOCK_STREAM, 0) = 13
[pid 19771] ioctl(13, FIOCLEX)          = 0
[pid 19771] connect(13, {sa_family=AF_LOCAL, sun_path="/usr/local/var/run/watchman/kayakyakr-state/sock"}, 110) = 0
[pid 19771] epoll_ctl(5, EPOLL_CTL_ADD, 11, {EPOLLOUT, {u32=11, u64=11}}) = 0
[pid 19771] epoll_ctl(5, EPOLL_CTL_ADD, 12, {EPOLLIN|EPOLLOUT, {u32=12, u64=12}}) = 0
[pid 19771] epoll_ctl(5, EPOLL_CTL_ADD, 13, {EPOLLIN|EPOLLOUT, {u32=13, u64=13}}) = 0
[pid 19771] epoll_wait(5, [{EPOLLOUT, {u32=13, u64=13}}, {EPOLLOUT, {u32=11, u64=11}}, {EPOLLOUT, {u32=12, u64=12}}, {EPOLLIN, {u32=8, u64=8}}], 1024, 481) = 4
[pid 19771] getsockopt(13, SOL_SOCKET, SO_ERROR, 0x7ffffd2ffe60, 0x7ffffd2ffe70) = -1 EINVAL (Invalid argument)

Could be related to https://github.com/Microsoft/BashOnWindows/issues/1343 which already has a fix inbound. That’s good.

@therealkenc this issue is not limited to 7.1. I think a few more people started hitting it with 7.1, but it existed for me in all versions I tried.

Just an update that Unix sockets now support the SO_ERROR socket option. The fix is in the dev branch and should soon make it to the release. Regarding #682, it’s not clear from the post, but I think that issue was for the SO_ERROR socket option for INET sockets.

I am working on the SMC_RIGHTS and SCM_CREDENTIALS as we speak 😃

I got the dates wrong. The ping was on the 8th. Had better shock value when I thought Sunil fixed it in an afternoon. Still, I was surprised when it worked for #610 and I didn’t say anything at the time.

Wow! That was ~6 hours ~4 days from ping to fix (edit: still impressive).

Does squeaking really work in this forum? Because it’s starting to look like it does. If so, finishing SCM_RIGHTS and SCM_CREDENTIALS (#1326 #514 #613) not to mention the clone() pattern GNU is newly fond of (#1005) or futexe()s in general (#1006) would unblock a ton 'o stuff. What’s the optimal whinge frequency?

Thanks @therealkenc for detailed info. As you already found out, the support for SO_ERROR in WSL is not complete. I have opened a bug internally to track this.