From: Stephan Bosch Date: Mon, 20 Oct 2014 15:54:27 +0000 (-0700) Subject: lib-http: client: Fixed behavior for max_connect_attempts with fewer IPs than attempts. X-Git-Tag: 2.2.15~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4e4b8544a492cf90bd7a93c9a26e8285fc7c00b;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Fixed behavior for max_connect_attempts with fewer IPs than attempts. This was broken by earlier 'fix'. --- diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index fbba1a4af8..fc149f40de 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -347,9 +347,8 @@ http_client_queue_requests_pending(struct http_client_queue *queue, void http_client_queue_connection_success(struct http_client_queue *queue, const struct http_client_peer_addr *addr); -bool -http_client_queue_connection_failure(struct http_client_queue *queue, - const struct http_client_peer_addr *addr, const char *reason); +void http_client_queue_connection_failure(struct http_client_queue *queue, + const struct http_client_peer_addr *addr, const char *reason); void http_client_queue_switch_ioloop(struct http_client_queue *queue); struct http_client_host * diff --git a/src/lib-http/http-client-queue.c b/src/lib-http/http-client-queue.c index 1137f28448..55c178ba33 100644 --- a/src/lib-http/http-client-queue.c +++ b/src/lib-http/http-client-queue.c @@ -318,10 +318,12 @@ http_client_queue_connection_success(struct http_client_queue *queue, } } -bool +void http_client_queue_connection_failure(struct http_client_queue *queue, const struct http_client_peer_addr *addr, const char *reason) { + const struct http_client_settings *set = + &queue->client->set; struct http_client_host *host = queue->host; http_client_queue_debug(queue, "Failed to set up connection to %s%s: %s " @@ -332,6 +334,7 @@ http_client_queue_connection_failure(struct http_client_queue *queue, (array_is_created(&queue->pending_peers) ? array_count(&queue->pending_peers): 0), array_count(&queue->requests)); + if (array_is_created(&queue->pending_peers) && array_count(&queue->pending_peers) > 0) { struct http_client_peer *const *peer_idx; @@ -350,7 +353,7 @@ http_client_queue_connection_failure(struct http_client_queue *queue, if (array_count(&queue->pending_peers) > 0) { http_client_queue_debug(queue, "Waiting for remaining pending peers."); - return TRUE; + return; } } @@ -361,21 +364,26 @@ http_client_queue_connection_failure(struct http_client_queue *queue, timeout_remove(&queue->to_connect); if (http_client_queue_is_last_connect_ip(queue)) { - http_client_queue_debug(queue, - "Failed to set up any connection; failing all queued requests"); - - /* all IPs failed, but retry all of them again on the - next request. */ + /* all IPs failed, but retry all of them again if we have more + connect attempts left or on the next request. */ queue->ips_connect_idx = queue->ips_connect_start_idx = (queue->ips_connect_idx + 1) % host->ips_count; - queue->connect_attempts = 0; - http_client_queue_fail(queue, - HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED, reason); - return FALSE; + + if (set->max_connect_attempts == 0 || + queue->connect_attempts >= set->max_connect_attempts) { + http_client_queue_debug(queue, + "Failed to set up any connection; failing all queued requests"); + queue->connect_attempts = 0; + http_client_queue_fail(queue, + HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED, reason); + return; + } + } else { + queue->ips_connect_idx = (queue->ips_connect_idx + 1) % host->ips_count; } - queue->ips_connect_idx = (queue->ips_connect_idx + 1) % host->ips_count; + http_client_queue_connection_setup(queue); - return TRUE; + return; } /*