From 87ef99e8bdcf44e309f78d5bbeb9234de2c4069c Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Fri, 21 Oct 2016 11:03:10 +0200
Subject: [PATCH] multi: force connections to get closed in
 close_all_connections
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Several independent reports on infinite loops haning in the
close_all_connections() when closing a multi handle can be fixed by
marking the connection to get closed before calling Curl_disconnect.

This is more fixing-the-sympthom rather than the underlying problem
though.

Bug: https://curl.haxx.se/mail/lib-2016-10/0011.html
Bug: https://curl.haxx.se/mail/lib-2016-10/0059.html

Reported-by: Dan Fandrich, Valentin David, Miloš Ljumović
---
 lib/multi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/multi.c b/lib/multi.c
index e81f5aa..bbeafd3 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -40,10 +40,11 @@
 #include "speedcheck.h"
 #include "conncache.h"
 #include "multihandle.h"
 #include "pipeline.h"
 #include "sigpipe.h"
+#include "connect.h"
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
 #include "curl_memory.h"
 #include "memdebug.h"
 
@@ -2174,10 +2175,11 @@ static void close_all_connections(struct Curl_multi *multi)
 
     sigpipe_ignore(conn->data, &pipe_st);
     conn->data->easy_conn = NULL; /* clear the easy handle's connection
                                      pointer */
     /* This will remove the connection from the cache */
+    connclose(conn, "kill all");
     (void)Curl_disconnect(conn, FALSE);
     sigpipe_restore(&pipe_st);
 
     conn = Curl_conncache_find_first_connection(&multi->conn_cache);
   }
-- 
2.9.3

