changeset 15482:6f940b2bfbe6

dsync: Fixed hang when sending mail stream to remote dsync.
author Timo Sirainen <tss@iki.fi>
date Sat, 15 Dec 2012 14:24:41 +0200
parents 1204e8bae160
children fc6873897e8b
files src/doveadm/dsync/dsync-ibc-stream.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-ibc-stream.c	Sat Dec 15 13:56:16 2012 +0200
+++ b/src/doveadm/dsync/dsync-ibc-stream.c	Sat Dec 15 14:24:41 2012 +0200
@@ -243,6 +243,7 @@
 	struct ostream *output = ibc->output;
 	int ret;
 
+	o_stream_cork(ibc->output);
 	if ((ret = o_stream_flush(output)) < 0)
 		ret = 1;
 	else if (ibc->mail_output != NULL) {
@@ -253,6 +254,7 @@
 
 	if (!dsync_ibc_is_send_queue_full(&ibc->ibc))
 		ibc->ibc.io_callback(ibc->ibc.io_context);
+	o_stream_uncork(ibc->output);
 	return ret;
 }
 
@@ -1368,7 +1370,11 @@
 		ibc->mail_output_last = '\0';
 		ibc->mail_output = mail->input;
 		i_stream_ref(ibc->mail_output);
-		(void)dsync_ibc_stream_send_mail_stream(ibc);
+		if (dsync_ibc_stream_send_mail_stream(ibc) == 0) {
+			/* flush callback isn't being called while output
+			   stream is corked */
+			o_stream_uncork(ibc->output);
+		}
 	}
 }
 
@@ -1471,7 +1477,8 @@
 	struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc;
 
 	o_stream_uncork(ibc->output);
-	o_stream_cork(ibc->output);
+	if (ibc->mail_output == NULL)
+		o_stream_cork(ibc->output);
 }
 
 static bool dsync_ibc_stream_is_send_queue_full(struct dsync_ibc *_ibc)