dovecot-2.2: lib-http: client: Fixed recovery after connection f...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 1 07:34:19 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/548cb71d63da
changeset: 17858:548cb71d63da
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed Oct 01 10:33:49 2014 +0300
description:
lib-http: client: Fixed recovery after connection failure.
If a parallel already connected connection was active, the queue wasn't notified of the failure.
Only pending connections should be considered in this case and not established ones.

diffstat:

 src/lib-http/http-client-peer.c    |  41 +++++++++++++++++++++++++++----------
 src/lib-http/http-client-private.h |   5 +++-
 2 files changed, 34 insertions(+), 12 deletions(-)

diffs (96 lines):

diff -r adcf35ac5432 -r 548cb71d63da src/lib-http/http-client-peer.c
--- a/src/lib-http/http-client-peer.c	Wed Oct 01 10:33:39 2014 +0300
+++ b/src/lib-http/http-client-peer.c	Wed Oct 01 10:33:49 2014 +0300
@@ -529,22 +529,28 @@
 {
 	const struct http_client_settings *set = &peer->client->set;
 	struct http_client_queue *const *queue;
-	unsigned int num_urgent;
-
-	i_assert(array_count(&peer->conns) > 0);
-
-	http_client_peer_debug(peer, "Failed to make connection");
+	unsigned int pending;
 
 	peer->last_failure = ioloop_timeval;
 
-	if (array_count(&peer->conns) == 1) {
+	/* count number of pending connections */
+	pending = http_client_peer_pending_connections(peer);
+	i_assert(pending > 0);
+
+	http_client_peer_debug(peer,
+		"Failed to make connection "
+		"(connections=%u, connecting=%u)",
+		array_count(&peer->conns), pending);
+
+	/* manage backoff timer only when this was the only attempt */
+	if (pending == 1) {
 		if (peer->backoff_time_msecs == 0)
 			peer->backoff_time_msecs = set->connect_backoff_time_msecs;
 		else
 			peer->backoff_time_msecs *= 2;
 	}
 
-	if (array_count(&peer->conns) > 1) {
+	if (pending > 1) {
 		/* if there are other connections attempting to connect, wait
 		   for them before failing the requests. remember that we had
 		   trouble with connecting so in future we don't try to create
@@ -558,9 +564,6 @@
 			http_client_queue_connection_failure(*queue, &peer->addr, reason);
 		}
 	}
-	if (array_count(&peer->conns) == 0 &&
-	    http_client_peer_requests_pending(peer, &num_urgent) == 0)
-		http_client_peer_free(&peer);
 }
 
 void http_client_peer_connection_lost(struct http_client_peer *peer)
@@ -586,7 +589,8 @@
 		http_client_peer_free(&peer);
 }
 
-unsigned int http_client_peer_idle_connections(struct http_client_peer *peer)
+unsigned int
+http_client_peer_idle_connections(struct http_client_peer *peer)
 {
 	struct http_client_connection *const *conn_idx;
 	unsigned int idle = 0;
@@ -600,6 +604,21 @@
 	return idle;
 }
 
+unsigned int
+http_client_peer_pending_connections(struct http_client_peer *peer)
+{
+	struct http_client_connection *const *conn_idx;
+	unsigned int pending = 0;
+
+	/* find idle connections */
+	array_foreach(&peer->conns, conn_idx) {
+		if (!(*conn_idx)->closing && !(*conn_idx)->connected)
+			pending++;
+	}
+
+	return pending;
+}
+
 void http_client_peer_switch_ioloop(struct http_client_peer *peer)
 {
 	if (peer->to_req_handling != NULL) {
diff -r adcf35ac5432 -r 548cb71d63da src/lib-http/http-client-private.h
--- a/src/lib-http/http-client-private.h	Wed Oct 01 10:33:39 2014 +0300
+++ b/src/lib-http/http-client-private.h	Wed Oct 01 10:33:49 2014 +0300
@@ -308,7 +308,10 @@
 					 const char *reason);
 void http_client_peer_connection_lost(struct http_client_peer *peer);
 bool http_client_peer_is_connected(struct http_client_peer *peer);
-unsigned int http_client_peer_idle_connections(struct http_client_peer *peer);
+unsigned int
+http_client_peer_idle_connections(struct http_client_peer *peer);
+unsigned int
+http_client_peer_pending_connections(struct http_client_peer *peer);
 void http_client_peer_switch_ioloop(struct http_client_peer *peer);
 
 struct http_client_queue *


More information about the dovecot-cvs mailing list