>From 9a0c637b07be7b842b9be21488238d578f39d781 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 16 Dec 2015 14:40:17 +0200 Subject: [PATCH] Avoid hanging on MS-Windows when invoked with --connect-timeout * src/connect.c (connect_to_ip) [WIN32]: Don't call fd_close if the connection timed out, to avoid hanging. --- src/connect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/connect.c b/src/connect.c index 024b231..0704000 100644 --- a/src/connect.c +++ b/src/connect.c @@ -369,7 +369,14 @@ connect_to_ip (const ip_address *ip, int port, const char *print) logprintf. */ int save_errno = errno; if (sock >= 0) - fd_close (sock); + { +#ifdef WIN32 + /* If the connection timed out, fd_close will hang in Gnulib's + close_fd_maybe_socket, inside the call to WSAEnumNetworkEvents. */ + if (errno != ETIMEDOUT) +#endif + fd_close (sock); + } if (print) logprintf (LOG_NOTQUIET, _("failed: %s.\n"), strerror (errno)); errno = save_errno; -- 2.6.3.windows.1