dovecot-2.2: lib-master: Timeout anvil queries after 5 seconds.

dovecot at dovecot.org dovecot at dovecot.org
Wed Mar 11 14:41:02 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/ae12cfc7e064
changeset: 18325:ae12cfc7e064
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Mar 11 16:40:05 2015 +0200
description:
lib-master: Timeout anvil queries after 5 seconds.

diffstat:

 src/lib-master/anvil-client.c |  25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diffs (75 lines):

diff -r f7b3c923cf4d -r ae12cfc7e064 src/lib-master/anvil-client.c
--- a/src/lib-master/anvil-client.c	Wed Mar 11 16:39:24 2015 +0200
+++ b/src/lib-master/anvil-client.c	Wed Mar 11 16:40:05 2015 +0200
@@ -20,6 +20,7 @@
 	struct istream *input;
 	struct ostream *output;
 	struct io *io;
+	struct timeout *to_query;
 
 	struct timeout *to_reconnect;
 	time_t last_reconnect;
@@ -34,6 +35,7 @@
 #define ANVIL_HANDSHAKE "VERSION\tanvil\t1\t0\n"
 #define ANVIL_INBUF_SIZE 1024
 #define ANVIL_RECONNECT_MIN_SECS 5
+#define ANVIL_QUERY_TIMEOUT_MSECS (1000*5)
 
 static void anvil_client_disconnect(struct anvil_client *client);
 
@@ -116,6 +118,11 @@
 	} else if (client->input->eof) {
 		i_error("read(%s) failed: EOF", client->path);
 		anvil_reconnect(client);
+	} else if (client->to_query != NULL) {
+		if (aqueue_count(client->queries) == 0)
+			timeout_remove(&client->to_query);
+		else
+			timeout_reset(client->to_query);
 	}
 }
 
@@ -165,12 +172,14 @@
 		i_free(query);
 		aqueue_delete_tail(client->queries);
 	}
+	if (client->to_query != NULL)
+		timeout_remove(&client->to_query);
 }
 
 static void anvil_client_disconnect(struct anvil_client *client)
 {
+	anvil_client_cancel_queries(client);
 	if (client->fd != -1) {
-		anvil_client_cancel_queries(client);
 		io_remove(&client->io);
 		i_stream_destroy(&client->input);
 		o_stream_destroy(&client->output);
@@ -181,6 +190,16 @@
 		timeout_remove(&client->to_reconnect);
 }
 
+static void anvil_client_timeout(struct anvil_client *client)
+{
+	i_assert(aqueue_count(client->queries) > 0);
+
+	i_error("%s: Anvil queries timed out after %u secs - aborting queries",
+		client->path, ANVIL_QUERY_TIMEOUT_MSECS/1000);
+	/* perhaps reconnect helps */
+	anvil_reconnect(client);
+}
+
 static int anvil_client_send(struct anvil_client *client, const char *cmd)
 {
 	struct const_iovec iov[2];
@@ -190,6 +209,10 @@
 			return -1;
 	}
 
+	if (client->to_query == NULL) {
+		client->to_query = timeout_add(ANVIL_QUERY_TIMEOUT_MSECS,
+					       anvil_client_timeout, client);
+	}
 	iov[0].iov_base = cmd;
 	iov[0].iov_len = strlen(cmd);
 	iov[1].iov_base = "\n";


More information about the dovecot-cvs mailing list