dovecot-2.1: auth: Log a warning if auth client disconnects whil...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 18 16:17:05 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/2ecd0e90402a
changeset: 13722:2ecd0e90402a
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 18 16:15:24 2011 +0200
description:
auth: Log a warning if auth client disconnects while it still has pending requests.

diffstat:

 src/auth/auth-client-connection.c |  34 ++++++++++++++++++++++++++++++----
 src/auth/auth-request-handler.c   |   6 ++++++
 src/auth/auth-request-handler.h   |   2 ++
 3 files changed, 38 insertions(+), 4 deletions(-)

diffs (107 lines):

diff -r 80558d1b7040 -r 2ecd0e90402a src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c	Fri Nov 18 15:52:23 2011 +0200
+++ b/src/auth/auth-client-connection.c	Fri Nov 18 16:15:24 2011 +0200
@@ -26,6 +26,7 @@
 
 static ARRAY_DEFINE(auth_client_connections, struct auth_client_connection *);
 
+static void auth_client_disconnected(struct auth_client_connection **_conn);
 static void auth_client_connection_unref(struct auth_client_connection **_conn);
 static void auth_client_input(struct auth_client_connection *conn);
 
@@ -100,7 +101,7 @@
 		   see if the old connection is still there. */
 		i_assert(old != conn);
 		if (i_stream_read(old->input) == -1) {
-                        auth_client_connection_destroy(&old);
+			auth_client_disconnected(&old);
 			old = NULL;
 		}
 	}
@@ -128,7 +129,7 @@
 static int auth_client_output(struct auth_client_connection *conn)
 {
 	if (o_stream_flush(conn->output) < 0) {
-		auth_client_connection_destroy(&conn);
+		auth_client_disconnected(&conn);
 		return 1;
 	}
 
@@ -221,7 +222,7 @@
 		return;
 	case -1:
 		/* disconnected */
-		auth_client_connection_destroy(&conn);
+		auth_client_disconnected(&conn);
 		return;
 	case -2:
 		/* buffer full */
@@ -314,7 +315,7 @@
 	str_append(str, "\nDONE\n");
 
 	if (o_stream_send(conn->output, str_data(str), str_len(str)) < 0)
-		auth_client_connection_destroy(&conn);
+		auth_client_disconnected(&conn);
 
 	return conn;
 }
@@ -356,6 +357,31 @@
         auth_client_connection_unref(&conn);
 }
 
+static void auth_client_disconnected(struct auth_client_connection **_conn)
+{
+	struct auth_client_connection *conn = *_conn;
+	unsigned int request_count;
+	int err;
+
+	*_conn = NULL;
+
+	if (conn->input->stream_errno != 0)
+		err = conn->input->stream_errno;
+	else if (conn->output->stream_errno != 0)
+		err = conn->output->stream_errno;
+	else
+		err = 0;
+
+	request_count = conn->request_handler == NULL ? 0 :
+		auth_request_handler_get_request_count(conn->request_handler);
+	if (request_count > 0) {
+		i_warning("auth client %u disconnected with %u "
+			  "pending requests: %s", conn->pid, request_count,
+			  err == 0 ? "EOF" : strerror(err));
+	}
+	auth_client_connection_destroy(&conn);
+}
+
 static void auth_client_connection_unref(struct auth_client_connection **_conn)
 {
         struct auth_client_connection *conn = *_conn;
diff -r 80558d1b7040 -r 2ecd0e90402a src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c	Fri Nov 18 15:52:23 2011 +0200
+++ b/src/auth/auth-request-handler.c	Fri Nov 18 16:15:24 2011 +0200
@@ -59,6 +59,12 @@
 	return handler;
 }
 
+unsigned int
+auth_request_handler_get_request_count(struct auth_request_handler *handler)
+{
+	return hash_table_count(handler->requests);
+}
+
 void auth_request_handler_abort_requests(struct auth_request_handler *handler)
 {
 	struct hash_iterate_context *iter;
diff -r 80558d1b7040 -r 2ecd0e90402a src/auth/auth-request-handler.h
--- a/src/auth/auth-request-handler.h	Fri Nov 18 15:52:23 2011 +0200
+++ b/src/auth/auth-request-handler.h	Fri Nov 18 16:15:24 2011 +0200
@@ -46,6 +46,8 @@
 				const void *reply, size_t reply_size);
 void auth_request_handler_reply_continue(struct auth_request *request,
 					 const void *reply, size_t reply_size);
+unsigned int
+auth_request_handler_get_request_count(struct auth_request_handler *handler);
 bool auth_request_handler_master_request(struct auth_request_handler *handler,
 					 struct auth_master_connection *master,
 					 unsigned int id,


More information about the dovecot-cvs mailing list