]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap-client: Avoid infinite reconnection loops when retrying command fails
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 18 May 2017 14:36:27 +0000 (17:36 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 19 May 2017 07:13:55 +0000 (10:13 +0300)
reconnect_command_count wasn't calculated correctly, because the SELECT and
potentially other following sync commands weren't included in it.

src/lib-imap-client/imapc-client.h
src/lib-imap-client/imapc-connection.c

index 54dadbdff897a72b1e6dd26e7760422d259c4d4a..03afe4f752a6a330c0c2c50db7838e3f24bc5469 100644 (file)
@@ -52,7 +52,9 @@ enum imapc_command_flags {
           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 {
index 3a27241f102521cf62b15b3424a5db8c97bb6fb2..48a2a6e159ed3e9dd7d8efb65aeb3891124b6614 100644 (file)
@@ -300,6 +300,7 @@ imapc_connection_abort_commands_array(ARRAY_TYPE(imapc_command) *cmd_array,
                         (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);
@@ -1433,7 +1434,7 @@ static int imapc_connection_input_tagged(struct imapc_connection *conn)
        }
 
        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