changeset 22047:ec84babd5727

lib-imap-client: Avoid infinite reconnection loops when retrying command fails reconnect_command_count wasn't calculated correctly, because the SELECT and potentially other following sync commands weren't included in it.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 18 May 2017 17:36:27 +0300
parents f4076be3efe9
children 6946011b3b0a
files src/lib-imap-client/imapc-client.h src/lib-imap-client/imapc-connection.c
diffstat 2 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-client.h	Thu May 18 12:32:12 2017 +0300
+++ b/src/lib-imap-client/imapc-client.h	Thu May 18 17:36:27 2017 +0300
@@ -52,7 +52,9 @@
 	   finishes. */
 	IMAPC_COMMAND_FLAG_RETRIABLE	= 0x04,
 	/* This is the LOGOUT command. Use a small timeout for it. */
-	IMAPC_COMMAND_FLAG_LOGOUT	= 0x08
+	IMAPC_COMMAND_FLAG_LOGOUT	= 0x08,
+	/* Command is being resent after a reconnection. */
+	IMAPC_COMMAND_FLAG_RECONNECTED	= 0x10
 };
 
 enum imapc_client_ssl_mode {
--- a/src/lib-imap-client/imapc-connection.c	Thu May 18 12:32:12 2017 +0300
+++ b/src/lib-imap-client/imapc-connection.c	Thu May 18 17:36:27 2017 +0300
@@ -300,6 +300,7 @@
 			 (cmd->flags & IMAPC_COMMAND_FLAG_RETRIABLE) != 0) {
 			cmd->send_pos = 0;
 			cmd->wait_for_literal = 0;
+			cmd->flags |= IMAPC_COMMAND_FLAG_RECONNECTED;
 			i++;
 		} else {
 			array_delete(cmd_array, i, 1);
@@ -1435,7 +1436,7 @@
 	}
 
 	if (conn->reconnect_command_count > 0 &&
-	    (cmd->flags & IMAPC_COMMAND_FLAG_PRELOGIN) == 0) {
+	    (cmd->flags & IMAPC_COMMAND_FLAG_RECONNECTED) != 0) {
 		if (--conn->reconnect_command_count == 0) {
 			/* we've received replies for all the commands started
 			   before reconnection. if we get disconnected now, we