changeset 20708:f013cf80c12c

imap: Avoid wrongly assert-crashing in client_check_command_hangs() Fixes assert: Panic: file imap-client.c: line 837 (client_check_command_hangs): assertion failed: (client->io != NULL)
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 07 Sep 2016 11:52:00 +0300
parents a9bdefa7d022
children c2b0657d69df
files src/imap/imap-client.c
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-client.c	Thu Sep 08 20:23:35 2016 +0300
+++ b/src/imap/imap-client.c	Wed Sep 07 11:52:00 2016 +0300
@@ -840,7 +840,14 @@
 	for (cmd = client->command_queue; cmd != NULL; cmd = cmd->next) {
 		switch (cmd->state) {
 		case CLIENT_COMMAND_STATE_WAIT_INPUT:
-			i_assert(client->io != NULL);
+			/* We need to be reading input for this command.
+			   However, if there is already an output lock for
+			   another command we'll wait for it to finish first.
+			   This is needed because if there are any literals
+			   we'd need to send "+ OK" responses. */
+			i_assert(client->io != NULL ||
+				 (client->output_cmd_lock != NULL &&
+				  client->output_cmd_lock != client->input_lock));
 			unfinished_count++;
 			break;
 		case CLIENT_COMMAND_STATE_WAIT_OUTPUT:
@@ -1043,6 +1050,8 @@
 	if (client->input_lock != NULL) {
 		if (client->input_lock->state ==
 		    CLIENT_COMMAND_STATE_WAIT_UNAMBIGUITY ||
+		    /* we can't send literal "+ OK" replies if output is
+		       locked by another command. */
 		    (client->output_cmd_lock != NULL &&
 		     client->output_cmd_lock != client->input_lock)) {
 			*remove_io_r = TRUE;