X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_socket.c;h=0a4dd9a0f6abd68ee2e776f6311dfa710eaca565;hp=939aa9c4577b8e15d794e82aca1f3b43938e0c1b;hb=86a99c6b999671ed444711139db1937617e802a0;hpb=0c026f3c6dec784c3267ad7e2c4709d5393dc292 diff --git a/src/net_socket.c b/src/net_socket.c index 939aa9c4..0a4dd9a0 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -401,6 +401,17 @@ static void handle_meta_io(void *data, int flags) { connection_t *c = data; if(c->status.connecting) { + /* The event loop does not protect against spurious events. Verify that we are actually connected. */ + if (connect(c->socket, &c->address.sa, sizeof(c->address)) == 0) + logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Error while connecting to %s (%s): redundant connect() unexpectedly succeeded", c->name, c->hostname); + else if (!sockisconn(sockerrno)) { + if (!sockalready(sockerrno)) { + logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Error while checking connection status for %s (%s): %s", c->name, c->hostname, sockstrerror(sockerrno)); + terminate_connection(c, false); + } + return; + } + c->status.connecting = false; int result;