From: Timo Sirainen Date: Thu, 15 Dec 2016 15:31:18 +0000 (+0200) Subject: imapc: Fix infinite reconnect loop to remote server that is down X-Git-Tag: 2.3.0.rc1~2407 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af577c113808263cb7a9b8121e1c91ecaedacb59;p=thirdparty%2Fdovecot%2Fcore.git imapc: Fix infinite reconnect loop to remote server that is down This happened only in some situations. Usually there would have bene some command in the queue, which would cause the reconnect-check to fail. --- diff --git a/src/lib-imap-client/imapc-connection.c b/src/lib-imap-client/imapc-connection.c index 0f4e249e10..d52d877847 100644 --- a/src/lib-imap-client/imapc-connection.c +++ b/src/lib-imap-client/imapc-connection.c @@ -126,6 +126,7 @@ struct imapc_connection { struct timeout *to_throttle, *to_throttle_shrink; bool reconnecting:1; + bool reconnect_ok:1; bool idling:1; bool idle_stopping:1; bool idle_plus_waiting:1; @@ -150,6 +151,7 @@ imapc_connection_init(struct imapc_client *client) conn->name = i_strdup_printf("%s:%u", client->set.host, client->set.port); conn->literal.fd = -1; + conn->reconnect_ok = TRUE; i_array_init(&conn->cmd_send_queue, 8); i_array_init(&conn->cmd_wait_list, 32); i_array_init(&conn->literal_files, 4); @@ -434,12 +436,16 @@ static bool imapc_connection_can_reconnect(struct imapc_connection *conn) { if (conn->selected_box != NULL) return imapc_client_mailbox_can_reconnect(conn->selected_box); - else - return conn->reconnect_command_count == 0; + else { + return conn->reconnect_command_count == 0 && + conn->reconnect_ok; + } } static void imapc_connection_reconnect(struct imapc_connection *conn) { + conn->reconnect_ok = FALSE; + if (conn->selected_box != NULL) imapc_client_mailbox_reconnect(conn->selected_box); else { @@ -1371,6 +1377,10 @@ static int imapc_connection_input_tagged(struct imapc_connection *conn) conn->selected_box->reconnect_ok = TRUE; } } + if (conn->reconnect_command_count == 0) { + /* we've successfully received replies to some commands. */ + conn->reconnect_ok = TRUE; + } imapc_connection_input_reset(conn); imapc_command_reply_free(cmd, &reply); imapc_command_send_more(conn);