diff src/lmtp/lmtp-proxy.c @ 17513:119adb7d2479

lmtp: Create all proxy DATA streams before reading from them. I'm not sure if this actually fixes anything or not, but it's still safer to do it this way.
author Timo Sirainen <tss@iki.fi>
date Thu, 19 Jun 2014 15:50:40 +0300
parents 20e8ed98357b
children 1b9356dbfca2
line wrap: on
line diff
--- a/src/lmtp/lmtp-proxy.c	Thu Jun 19 15:15:24 2014 +0300
+++ b/src/lmtp/lmtp-proxy.c	Thu Jun 19 15:50:40 2014 +0300
@@ -296,12 +296,14 @@
 	struct lmtp_proxy_connection *const *conns;
 
 	i_assert(data_input->seekable);
+	i_assert(proxy->data_input == NULL);
 
 	proxy->finish_callback = callback;
 	proxy->finish_context = context;
 	proxy->data_input = data_input;
 	i_stream_ref(proxy->data_input);
 
+	/* create the data_input streams first */
 	array_foreach(&proxy->connections, conns) {
 		struct lmtp_proxy_connection *conn = *conns;
 
@@ -312,10 +314,18 @@
 
 		conn->to = timeout_add(proxy->max_timeout_msecs,
 				       lmtp_proxy_conn_timeout, conn);
+		conn->data_input = i_stream_create_limit(data_input, (uoff_t)-1);
+	}
+	/* now that all the streams are created, start reading them
+	   (reading them earlier could have caused the data_input parent's
+	   offset to change) */
+	array_foreach(&proxy->connections, conns) {
+		struct lmtp_proxy_connection *conn = *conns;
 
-		conn->data_input = i_stream_create_limit(data_input, (uoff_t)-1);
-		lmtp_client_send(conn->client, conn->data_input);
-		lmtp_client_send_more(conn->client);
+		if (conn->data_input != NULL) {
+			lmtp_client_send(conn->client, conn->data_input);
+			lmtp_client_send_more(conn->client);
+		}
 	}
 	/* finish if all of the connections have already failed */
 	lmtp_proxy_try_finish(proxy);