dovecot-2.0: lib-master: Added reconnection timeout to anvil cli...

dovecot at dovecot.org dovecot at dovecot.org
Fri Mar 4 20:54:36 EET 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/54e354cbf061
changeset: 12652:54e354cbf061
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 04 20:46:41 2011 +0200
description:
lib-master: Added reconnection timeout to anvil client.
Previously if anvil kept disconnecting, the client was rapidly flooding the
logs with errors.

diffstat:

 src/lib-master/anvil-client.c |  39 +++++++++++++++++++++++++++++----------
 1 files changed, 29 insertions(+), 10 deletions(-)

diffs (84 lines):

diff -r a6382acebe7e -r 54e354cbf061 src/lib-master/anvil-client.c
--- a/src/lib-master/anvil-client.c	Fri Mar 04 20:45:17 2011 +0200
+++ b/src/lib-master/anvil-client.c	Fri Mar 04 20:46:41 2011 +0200
@@ -21,6 +21,9 @@
 	struct ostream *output;
 	struct io *io;
 
+	struct timeout *to_reconnect;
+	time_t last_reconnect;
+
 	ARRAY_DEFINE(queries_arr, struct anvil_query);
 	struct aqueue *queries;
 
@@ -30,6 +33,7 @@
 
 #define ANVIL_HANDSHAKE "VERSION\tanvil\t1\t0\n"
 #define ANVIL_INBUF_SIZE 1024
+#define ANVIL_RECONNECT_MIN_SECS 5
 
 static void anvil_client_disconnect(struct anvil_client *client);
 
@@ -59,6 +63,7 @@
 	array_free(&client->queries_arr);
 	aqueue_deinit(&client->queries);
 	i_free(client->path);
+	i_assert(client->to_reconnect == NULL);
 	i_free(client);
 }
 
@@ -71,7 +76,17 @@
 			return;
 		}
 	}
-	(void)anvil_client_connect(client, FALSE);
+
+	if (ioloop_time - client->last_reconnect < ANVIL_RECONNECT_MIN_SECS) {
+		if (client->to_reconnect == NULL) {
+			client->to_reconnect =
+				timeout_add(ANVIL_RECONNECT_MIN_SECS,
+					    anvil_reconnect, client);
+		}
+	} else {
+		client->last_reconnect = ioloop_time;
+		(void)anvil_client_connect(client, FALSE);
+	}
 }
 
 static void anvil_input(struct anvil_client *client)
@@ -119,6 +134,9 @@
 		return -1;
 	}
 
+	if (client->to_reconnect != NULL)
+		timeout_remove(&client->to_reconnect);
+
 	client->fd = fd;
 	client->input = i_stream_create_fd(fd, ANVIL_INBUF_SIZE, FALSE);
 	client->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
@@ -142,15 +160,16 @@
 
 static void anvil_client_disconnect(struct anvil_client *client)
 {
-	if (client->fd == -1)
-		return;
-
-	anvil_client_cancel_queries(client);
-	io_remove(&client->io);
-	i_stream_destroy(&client->input);
-	o_stream_destroy(&client->output);
-	net_disconnect(client->fd);
-	client->fd = -1;
+	if (client->fd != -1) {
+		anvil_client_cancel_queries(client);
+		io_remove(&client->io);
+		i_stream_destroy(&client->input);
+		o_stream_destroy(&client->output);
+		net_disconnect(client->fd);
+		client->fd = -1;
+	}
+	if (client->to_reconnect != NULL)
+		timeout_remove(&client->to_reconnect);
 }
 
 static int anvil_client_send(struct anvil_client *client, const char *cmd)


More information about the dovecot-cvs mailing list