dovecot-2.2: lib-http: If host can't be connected to, don't keep...

dovecot at dovecot.org dovecot at dovecot.org
Sun Mar 10 19:54:57 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/69407b54a557
changeset: 16010:69407b54a557
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Mar 10 19:54:51 2013 +0200
description:
lib-http: If host can't be connected to, don't keep retrying with more than one connection.
This also fixes infinitely trying to reconnect to host and retry.

diffstat:

 src/lib-http/http-client-connection.c |   1 +
 src/lib-http/http-client-peer.c       |  16 ++++++++++++++--
 src/lib-http/http-client-private.h    |   1 +
 3 files changed, 16 insertions(+), 2 deletions(-)

diffs (60 lines):

diff -r 0eaa4fddd61d -r 69407b54a557 src/lib-http/http-client-connection.c
--- a/src/lib-http/http-client-connection.c	Sun Mar 10 18:37:46 2013 +0200
+++ b/src/lib-http/http-client-connection.c	Sun Mar 10 19:54:51 2013 +0200
@@ -615,6 +615,7 @@
 	struct stat st;
 
 	conn->connected = TRUE;
+	conn->peer->last_connect_failed = FALSE;
 
 	if (conn->client->set.rawlog_dir != NULL &&
 		stat(conn->client->set.rawlog_dir, &st) == 0) {
diff -r 0eaa4fddd61d -r 69407b54a557 src/lib-http/http-client-peer.c
--- a/src/lib-http/http-client-peer.c	Sun Mar 10 18:37:46 2013 +0200
+++ b/src/lib-http/http-client-peer.c	Sun Mar 10 19:54:51 2013 +0200
@@ -175,7 +175,12 @@
 	}
 
 	/* yes, determine how many connections to set up */
-	if (num_urgent == 0) {
+	if (peer->last_connect_failed && array_count(&peer->conns) > 0 &&
+	    array_count(&peer->conns) == connecting+closing) {
+		/* don't create new connections until the existing ones have
+		   finished connecting successfully. */
+		new_connections = 0;
+	} else if (num_urgent == 0) {
 		new_connections = 1;
 	} else {
 		new_connections = (num_urgent > connecting ? num_urgent - connecting : 0);
@@ -339,12 +344,19 @@
 void http_client_peer_connection_failure(struct http_client_peer *peer)
 {
 	struct http_client_host *const *host;
+	unsigned int num_urgent;
 
 	i_assert(array_count(&peer->conns) > 0);
 
 	http_client_peer_debug(peer, "Failed to make connection");
 
-	if (array_count(&peer->conns) == 1) {
+	if (array_count(&peer->conns) > 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
+		   more than one connection until connects work again. */
+		peer->last_connect_failed = TRUE;
+	} else {
 		/* this was the only/last connection and connecting to it
 		   failed. a second connect will probably also fail, so just
 		   abort all requests. */
diff -r 0eaa4fddd61d -r 69407b54a557 src/lib-http/http-client-private.h
--- a/src/lib-http/http-client-private.h	Sun Mar 10 18:37:46 2013 +0200
+++ b/src/lib-http/http-client-private.h	Sun Mar 10 19:54:51 2013 +0200
@@ -120,6 +120,7 @@
 
 	unsigned int destroyed:1;        /* peer is being destroyed */
 	unsigned int no_payload_sync:1;  /* expect: 100-continue failed before */
+	unsigned int last_connect_failed:1;
 };
 
 struct http_client_connection {


More information about the dovecot-cvs mailing list