dovecot-2.2: lib-http: client: If peer is unlinked from queue an...

dovecot at dovecot.org dovecot at dovecot.org
Tue Oct 21 20:59:53 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/df5be9847b13
changeset: 17977:df5be9847b13
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Tue Oct 21 23:34:50 2014 +0300
description:
lib-http: client: If peer is unlinked from queue and no other links remain, close any pending connections.
Those pending connections would no longer serve any purpose.

diffstat:

 src/lib-http/http-client-peer.c |  42 ++++++++++++++++++++++++++++++----------
 1 files changed, 31 insertions(+), 11 deletions(-)

diffs (81 lines):

diff -r 0de24ac413c4 -r df5be9847b13 src/lib-http/http-client-peer.c
--- a/src/lib-http/http-client-peer.c	Tue Oct 21 05:46:22 2014 +0300
+++ b/src/lib-http/http-client-peer.c	Tue Oct 21 23:34:50 2014 +0300
@@ -157,6 +157,23 @@
 	return FALSE;
 }
 
+static void
+http_client_peer_disconnect(struct http_client_peer *peer)
+{
+	struct http_client_connection **conn;
+	ARRAY_TYPE(http_client_connection) conns;
+
+	http_client_peer_debug(peer, "Peer disconnect");
+
+	/* make a copy of the connection array; freed connections modify it */
+	t_array_init(&conns, array_count(&peer->conns));
+	array_copy(&conns.arr, 0, &peer->conns.arr, 0, array_count(&peer->conns));
+	array_foreach_modifiable(&conns, conn) {
+		http_client_connection_unref(conn);
+	}
+	i_assert(array_count(&peer->conns) == 0);
+}
+
 static void http_client_peer_check_idle(struct http_client_peer *peer)
 {
 	struct http_client_connection *const *conn_idx;
@@ -200,6 +217,13 @@
 	/* FIXME: limit the number of requests handled in one run to prevent
 	   I/O starvation. */
 
+	/* disconnect if we're not linked to any queue anymore */
+	if (array_count(&peer->queues) == 0) {
+		i_assert(peer->to_backoff != NULL);
+		http_client_peer_disconnect(peer);
+		return;
+	}
+
 	/* don't do anything unless we have pending requests */
 	num_pending = http_client_peer_requests_pending(peer, &num_urgent);
 	if (num_pending == 0) {
@@ -426,8 +450,6 @@
 void http_client_peer_free(struct http_client_peer **_peer)
 {
 	struct http_client_peer *peer = *_peer;
-	struct http_client_connection **conn;
-	ARRAY_TYPE(http_client_connection) conns;
 
 	if (peer->destroyed)
 		return;
@@ -440,14 +462,7 @@
 	if (peer->to_backoff != NULL)
 		timeout_remove(&peer->to_backoff);
 
-	/* make a copy of the connection array; freed connections modify it */
-	t_array_init(&conns, array_count(&peer->conns));
-	array_copy(&conns.arr, 0, &peer->conns.arr, 0, array_count(&peer->conns));
-	array_foreach_modifiable(&conns, conn) {
-		http_client_connection_unref(conn);
-	}
-
-	i_assert(array_count(&peer->conns) == 0);
+	http_client_peer_disconnect(peer);
 	array_free(&peer->conns);
 	array_free(&peer->queues);
 
@@ -502,8 +517,13 @@
 			array_delete(&peer->queues,
 				array_foreach_idx(&peer->queues, queue_idx), 1);
 			if (array_count(&peer->queues) == 0) {
-				if (!http_client_peer_start_backoff_timer(peer))
+				if (http_client_peer_start_backoff_timer(peer)) {
+					/* will disconnect any pending connections */
+					http_client_peer_trigger_request_handler(peer);
+				} else {
+					/* drop peer immediately */
 					http_client_peer_free(&peer);
+				}
 			}
 			return;
 		}


More information about the dovecot-cvs mailing list