mdlayher / vsock

Package vsock provides access to Linux VM sockets (AF_VSOCK) for communication between a hypervisor and its virtual machines. MIT Licensed.
MIT License
328 stars 65 forks source link

vsock: Dial to a non-existent listener hangs instead of returning an error #47

Closed mdlayher closed 2 years ago

mdlayher commented 2 years ago

See https://github.com/lxc/lxd/pull/9894 for details.

This is likely due to the added use of nonblocking connect(2), but there should be some way to add error reporting. This will likely get plumbed into the socket package.

mdlayher commented 2 years ago

Here's the fix, and it looks like the stdlib does this too:

       EINPROGRESS
              The socket is nonblocking and the connection cannot be completed immediately.  (UNIX domain sockets failed with EAGAIN  instead.)   It  is  possible  to  select(2)  or
              poll(2)  for  completion by selecting the socket for writing.  After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET
              to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason
              for the failure).