dovecot-2.2: lib-http: client: Fixed aborting request in the mid...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 1 07:34:18 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/adcf35ac5432
changeset: 17857:adcf35ac5432
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed Oct 01 10:33:39 2014 +0300
description:
lib-http: client: Fixed aborting request in the middle of sending payload.
If the request payload is so big that it cannot be sent all at once, the
caller may at some point abort the request when it is still being sent. The
bug occurred when the request finally finished sending. It erroneously
advanced the state to WAITING rather than remaining ABORTED, thus
'reviving' the request unexpectedly.

diffstat:

 src/lib-http/http-client-connection.c |   1 +
 src/lib-http/http-client-request.c    |  13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diffs (40 lines):

diff -r df53b5ccc2ba -r adcf35ac5432 src/lib-http/http-client-connection.c
--- a/src/lib-http/http-client-connection.c	Wed Oct 01 00:17:09 2014 +0300
+++ b/src/lib-http/http-client-connection.c	Wed Oct 01 10:33:39 2014 +0300
@@ -299,6 +299,7 @@
 	if (conn->peer->no_payload_sync)
 		req->payload_sync = FALSE;
 
+	i_assert(req->state == HTTP_REQUEST_STATE_QUEUED);
 	array_append(&conn->request_wait_list, &req, 1);
 	http_client_request_ref(req);
 
diff -r df53b5ccc2ba -r adcf35ac5432 src/lib-http/http-client-request.c
--- a/src/lib-http/http-client-request.c	Wed Oct 01 00:17:09 2014 +0300
+++ b/src/lib-http/http-client-request.c	Wed Oct 01 10:33:39 2014 +0300
@@ -453,14 +453,23 @@
 {
 	i_assert(req->conn != NULL);
 
+	/* drop payload output stream */
 	if (req->payload_output != NULL) {
 		o_stream_unref(&req->payload_output);
 		req->payload_output = NULL;
 	}
-	req->state = HTTP_REQUEST_STATE_WAITING;
+
+	/* advance state only when request didn't get aborted in the mean time */
+	if (req->state != HTTP_REQUEST_STATE_ABORTED) {
+		i_assert(req->state == HTTP_REQUEST_STATE_PAYLOAD_OUT);
+		req->state = HTTP_REQUEST_STATE_WAITING;
+	}
+
+	/* release connection */
 	req->conn->output_locked = FALSE;
 
-	http_client_request_debug(req, "Finished sending payload");
+	http_client_request_debug(req, "Finished sending%s payload",
+		(req->state == HTTP_REQUEST_STATE_ABORTED ? " aborted" : ""));
 }
 
 static int


More information about the dovecot-cvs mailing list