Skip to content

Commit

Permalink
lib-imap-client: Avoid infinite reconnection loops when retrying comm…
Browse files Browse the repository at this point in the history
…and fails

reconnect_command_count wasn't calculated correctly, because the SELECT and
potentially other following sync commands weren't included in it.
  • Loading branch information
sirainen authored and GitLab committed May 19, 2017
1 parent cb4d75e commit e266d02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib-imap-client/imapc-client.h
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/lib-imap-client/imapc-connection.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e266d02

Please sign in to comment.