dovecot-2.2: lib-http: client: Fixed behavior of connection back...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 20 15:55:24 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/1ddc6c86de78
changeset: 17971:1ddc6c86de78
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Oct 20 08:54:27 2014 -0700
description:
lib-http: client: Fixed behavior of connection backoff timer when multiple IPs are returned for hostname.
Peer backoff data was lost because peer was destroyed quickly. Now the peer
object is retained during the backoff period, so that new connection
attempts adhere to the backoff period.

diffstat:

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

diffs (87 lines):

diff -r 7d3325713356 -r 1ddc6c86de78 src/lib-http/http-client-peer.c
--- a/src/lib-http/http-client-peer.c	Mon Oct 20 08:54:27 2014 -0700
+++ b/src/lib-http/http-client-peer.c	Mon Oct 20 08:54:27 2014 -0700
@@ -91,7 +91,6 @@
 	}
 }
 
-
 static void
 http_client_peer_connect_backoff(struct http_client_peer *peer)
 {
@@ -101,18 +100,25 @@
 		"Backoff timer expired");
 
 	timeout_remove(&peer->to_backoff);
+
+	if (array_count(&peer->queues) == 0) {
+		http_client_peer_free(&peer);
+		return;
+	}
+
 	http_client_peer_do_connect(peer, 1);
 }
 
-static void
-http_client_peer_connect(struct http_client_peer *peer, unsigned int count)
+static bool
+http_client_peer_start_backoff_timer(struct http_client_peer *peer)
 {
 	if (peer->to_backoff != NULL)
-		return;
+		return TRUE;
 
 	if (peer->last_failure.tv_sec > 0) {
 		int backoff_time_spent =
 			timeval_diff_msecs(&ioloop_timeval, &peer->last_failure);
+
 		if (backoff_time_spent < (int)peer->backoff_time_msecs) {
 			http_client_peer_debug(peer,
 				"Starting backoff timer for %d msecs",
@@ -120,9 +126,21 @@
 			peer->to_backoff = timeout_add
 				((unsigned int)(peer->backoff_time_msecs - backoff_time_spent),
 					http_client_peer_connect_backoff, peer);
-			return;
+			return TRUE;
 		}
+
+		http_client_peer_debug(peer,
+			"Backoff time already exceeded by %d msecs",
+			backoff_time_spent - peer->backoff_time_msecs);
 	}
+	return FALSE;
+}
+
+static void
+http_client_peer_connect(struct http_client_peer *peer, unsigned int count)
+{
+	if (http_client_peer_start_backoff_timer(peer))
+		return;
 
 	http_client_peer_do_connect(peer, count);
 }
@@ -483,8 +501,10 @@
 		if (*queue_idx == queue) {
 			array_delete(&peer->queues,
 				array_foreach_idx(&peer->queues, queue_idx), 1);
-			if (array_count(&peer->queues) == 0)
-				http_client_peer_free(&peer);
+			if (array_count(&peer->queues) == 0) {
+				if (!http_client_peer_start_backoff_timer(peer))
+					http_client_peer_free(&peer);
+			}
 			return;
 		}
 	}
@@ -511,6 +531,10 @@
 {
 	struct http_client_queue *const *queue;
 
+	http_client_peer_debug(peer,
+		"Successfully connected (connections=%u)",
+		array_count(&peer->conns));
+
 	peer->last_failure.tv_sec = peer->last_failure.tv_usec = 0;
 	peer->backoff_time_msecs = 0;
 


More information about the dovecot-cvs mailing list