From: Timo Sirainen Date: Wed, 10 Jul 2013 00:27:52 +0000 (+0300) Subject: lib-http: Fix/cleanup to handling connect failures. X-Git-Tag: 2.2.5~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3289b68d4c2e90fc369ea41539d49a6746764de;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Fix/cleanup to handling connect failures. There was some kind of double-error handling which messed up things. --- diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index 3fc644f723..39085c6d46 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -694,6 +694,7 @@ http_client_connection_ready(struct http_client_connection *conn) struct stat st; conn->connected = TRUE; + conn->connect_succeeded = TRUE; if (conn->to_connect != NULL && (conn->ssl_iostream == NULL || ssl_iostream_is_handshaked(conn->ssl_iostream))) @@ -952,10 +953,10 @@ void http_client_connection_unref(struct http_client_connection **_conn) } } + if (conn->connect_succeeded) + http_client_peer_connection_lost(peer); i_free(conn); *_conn = NULL; - - http_client_peer_connection_lost(peer); } void http_client_connection_switch_ioloop(struct http_client_connection *conn) diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index d81e824fd7..4531733522 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -329,17 +329,20 @@ void http_client_peer_connection_lost(struct http_client_peer *peer) { unsigned int num_urgent; + /* we get here when an already connected connection fails. if the + connect itself fails, http_client_peer_connection_failure() is + called instead. */ + if (peer->destroyed) return; http_client_peer_debug(peer, "Lost a connection (%d connections left)", array_count(&peer->conns)); - if (!peer->last_connect_failed) { - /* if there are pending requests, create a new - connection for them. */ - http_client_peer_handle_requests(peer); - } + /* if there are pending requests for this peer, create a new connection + for them. */ + http_client_peer_handle_requests(peer); + if (array_count(&peer->conns) == 0 && http_client_peer_requests_pending(peer, &num_urgent) == 0) http_client_peer_free(&peer); diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 44e885f608..35cc724f6f 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -159,6 +159,7 @@ struct http_client_connection { ARRAY_TYPE(http_client_request) request_wait_list; unsigned int connected:1; /* connection is connected */ + unsigned int connect_succeeded:1; unsigned int closing:1; unsigned int close_indicated:1; unsigned int output_locked:1; /* output is locked; no pipelining */