From e2eef799f8a7e675b0b1b507bd61c3032225ed5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 18 Mar 2018 12:13:13 +0100 Subject: [PATCH] Fix cancellation of connectTCP in case of early errors. Certain errors will result in an invalid handle to be returned from eventDriver.sockets.connectStream. In that case it is invalid to call cancelConnect. Also adds an additional debug log message including a stack trace in case of exceptions thrown from connection handlers. --- source/vibe/core/net.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index bb1dd67..e4dc73f 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -39,6 +39,7 @@ NetworkAddress resolveHost(string host, ushort address_family, bool use_dns = tr else import core.sys.posix.netinet.in_ : sockaddr_in, sockaddr_in6; enforce(host.length > 0, "Host name must not be empty."); + // FIXME: this check needs to be more specific to not disallow valid DNS names if (host[0] == ':' || host[0] >= '0' && host[0] <= '9') { auto addr = parseAddress(host); enforce(address_family == AddressFamily.UNSPEC || addr.addressFamily == address_family); @@ -135,6 +136,7 @@ TCPListener listenTCP(ushort port, void delegate(TCPConnection) connection_callb catch (Exception e) { logError("Handling of connection failed: %s", e.msg); conn.close(); + logDebug("Full error: %s", e); } }, address, options); } @@ -204,7 +206,8 @@ TCPConnection connectTCP(NetworkAddress addr, NetworkAddress bind_address = anyA cb => eventDriver.sockets.connectStream(uaddr, baddr, cb), (cb, sock_fd) { cancelled = true; - eventDriver.sockets.cancelConnectStream(sock_fd); + if (sock_fd != SocketFD.invalid) + eventDriver.sockets.cancelConnectStream(sock_fd); }, (fd, st) { sock = fd; status = st; } );