First of all I would like to say that this is another problem than this one: Similar but not the same
My code looks like this:
struct addrinfo hints,
This is correct behavior, because a pending error causes a socket to become both readable and writable. As with any other system call, you need to check for error conditions explicitly. You could include the socket in the exception fdset (the fourth argument to select()), and pick up a notification directly, or you could check later for an error in a number of ways.
Be careful of writing to the socket, as a SIGPIPE could happen. In general, you should set a SIGPIPE handler and handle the error synchronously with EPIPE.