changeset 12065:ff5a47012287

director: If outgoing connection dies soon, mark the host as failed to avoid immediate reconnect.
author Timo Sirainen <tss@iki.fi>
date Thu, 02 Sep 2010 15:35:21 +0100
parents d55d6a72a043
children 4d8b54fc4ef5
files src/director/director-connection.c
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/director/director-connection.c	Thu Sep 02 13:50:17 2010 +0100
+++ b/src/director/director-connection.c	Thu Sep 02 15:35:21 2010 +0100
@@ -34,12 +34,16 @@
 #define DIRECTOR_CONNECTION_PING_INTERVAL_MSECS (15*1000)
 /* How long to wait before sending PING while waiting for SYNC reply */
 #define DIRECTOR_CONNECTION_SYNC_TIMEOUT_MSECS 1000
+/* If outgoing director connection exists for less than this many seconds,
+   mark the host as failed so we won't try to reconnect to it immediately */
+#define DIRECTOR_SUCCESS_MIN_CONNECT_SECS 10
 
 struct director_connection {
 	struct director_connection *prev, *next;
 
 	struct director *dir;
 	char *name;
+	time_t created;
 
 	/* for incoming connections the director host isn't known until
 	   ME-line is received */
@@ -887,6 +891,7 @@
 	struct director_connection *conn;
 
 	conn = i_new(struct director_connection, 1);
+	conn->created = ioloop_time;
 	conn->fd = fd;
 	conn->dir = dir;
 	conn->input = i_stream_create_fd(conn->fd, MAX_INBUF_SIZE, FALSE);
@@ -991,6 +996,10 @@
 
 	*_conn = NULL;
 
+	if (conn->host != NULL && !conn->in &&
+	    conn->created + DIRECTOR_SUCCESS_MIN_CONNECT_SECS > ioloop_time)
+		conn->host->last_failed = ioloop_time;
+
 	DLLIST_REMOVE(&dir->connections, conn);
 	if (dir->left == conn)
 		dir->left = NULL;