dovecot-2.2: lib-http: client: Fixed behavior for max_connect_at...

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/c9ea647cba87
changeset: 17969:c9ea647cba87
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Oct 20 08:54:27 2014 -0700
description:
lib-http: client: Fixed behavior for max_connect_attempts with fewer IPs than attempts.
This was broken by earlier 'fix'.

diffstat:

 src/lib-http/http-client-private.h |   5 ++---
 src/lib-http/http-client-queue.c   |  34 +++++++++++++++++++++-------------
 2 files changed, 23 insertions(+), 16 deletions(-)

diffs (87 lines):

diff -r c5f81685571f -r c9ea647cba87 src/lib-http/http-client-private.h
--- a/src/lib-http/http-client-private.h	Mon Oct 20 08:54:26 2014 -0700
+++ b/src/lib-http/http-client-private.h	Mon Oct 20 08:54:27 2014 -0700
@@ -347,9 +347,8 @@
 void
 http_client_queue_connection_success(struct http_client_queue *queue,
 					 const struct http_client_peer_addr *addr);
-bool
-http_client_queue_connection_failure(struct http_client_queue *queue,
-	const struct http_client_peer_addr *addr, const char *reason);
+void http_client_queue_connection_failure(struct http_client_queue *queue,
+ 	const struct http_client_peer_addr *addr, const char *reason);
 void http_client_queue_switch_ioloop(struct http_client_queue *queue);
 
 struct http_client_host *
diff -r c5f81685571f -r c9ea647cba87 src/lib-http/http-client-queue.c
--- a/src/lib-http/http-client-queue.c	Mon Oct 20 08:54:26 2014 -0700
+++ b/src/lib-http/http-client-queue.c	Mon Oct 20 08:54:27 2014 -0700
@@ -318,10 +318,12 @@
 	}
 }
 
-bool
+void
 http_client_queue_connection_failure(struct http_client_queue *queue,
 	const struct http_client_peer_addr *addr, const char *reason)
 {
+	const struct http_client_settings *set =
+		&queue->client->set;
 	struct http_client_host *host = queue->host;
 
 	http_client_queue_debug(queue, "Failed to set up connection to %s%s: %s "
@@ -332,6 +334,7 @@
 		(array_is_created(&queue->pending_peers) ?
 		 	array_count(&queue->pending_peers): 0),
 		array_count(&queue->requests));
+
 	if (array_is_created(&queue->pending_peers) &&
 		array_count(&queue->pending_peers) > 0) {
 		struct http_client_peer *const *peer_idx;
@@ -350,7 +353,7 @@
 		if (array_count(&queue->pending_peers) > 0) {
 			http_client_queue_debug(queue,
 				"Waiting for remaining pending peers.");
-			return TRUE;
+			return;
 		}
 	}
 
@@ -361,21 +364,26 @@
 		timeout_remove(&queue->to_connect);
 
 	if (http_client_queue_is_last_connect_ip(queue)) {
-		http_client_queue_debug(queue,
-			"Failed to set up any connection; failing all queued requests");
-
-		/* all IPs failed, but retry all of them again on the
-		   next request. */
+		/* all IPs failed, but retry all of them again if we have more
+		   connect attempts left or on the next request. */
 		queue->ips_connect_idx = queue->ips_connect_start_idx =
 			(queue->ips_connect_idx + 1) % host->ips_count;
-		queue->connect_attempts = 0;
-		http_client_queue_fail(queue,
-			HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED, reason);
-		return FALSE;
+
+		if (set->max_connect_attempts == 0 ||
+			queue->connect_attempts >= set->max_connect_attempts) {
+			http_client_queue_debug(queue,
+				"Failed to set up any connection; failing all queued requests");
+			queue->connect_attempts = 0;
+			http_client_queue_fail(queue,
+				HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED, reason);
+			return;
+		}
+	} else {
+		queue->ips_connect_idx = (queue->ips_connect_idx + 1) % host->ips_count;
 	}
-	queue->ips_connect_idx = (queue->ips_connect_idx + 1) % host->ips_count;
+	
 	http_client_queue_connection_setup(queue);
-	return TRUE;
+	return;
 }
 
 /*


More information about the dovecot-cvs mailing list