dovecot-2.2: lib-http: client: Added support for attempting a si...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Sep 10 10:45:45 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/650629de6a73
changeset: 17774:650629de6a73
user: Stephan Bosch <stephan at rename-it.nl>
date: Wed Sep 10 13:39:37 2014 +0300
description:
lib-http: client: Added support for attempting a single IP several times.
Also limits the number of attempts when there are many IPs.
diffstat:
src/lib-http/http-client-private.h | 2 ++
src/lib-http/http-client-queue.c | 23 ++++++++++++++++++++---
src/lib-http/http-client.c | 1 +
src/lib-http/http-client.h | 11 +++++++++++
4 files changed, 34 insertions(+), 3 deletions(-)
diffs (104 lines):
diff -r bf371c4fed6e -r 650629de6a73 src/lib-http/http-client-private.h
--- a/src/lib-http/http-client-private.h Wed Sep 10 13:39:37 2014 +0300
+++ b/src/lib-http/http-client-private.h Wed Sep 10 13:39:37 2014 +0300
@@ -182,6 +182,8 @@
connected IP */
unsigned int ips_connect_start_idx;
+ unsigned int connect_attempts;
+
/* peers we are trying to connect to;
this can be more than one when soft connect timeouts are enabled */
ARRAY_TYPE(http_client_peer) pending_peers;
diff -r bf371c4fed6e -r 650629de6a73 src/lib-http/http-client-queue.c
--- a/src/lib-http/http-client-queue.c Wed Sep 10 13:39:37 2014 +0300
+++ b/src/lib-http/http-client-queue.c Wed Sep 10 13:39:37 2014 +0300
@@ -158,13 +158,20 @@
static bool
http_client_queue_is_last_connect_ip(struct http_client_queue *queue)
{
+ const struct http_client_settings *set =
+ &queue->client->set;
struct http_client_host *host = queue->host;
i_assert(queue->ips_connect_idx < host->ips_count);
i_assert(queue->ips_connect_start_idx < host->ips_count);
- /* we'll always go through all the IPs. we don't necessarily start
- connecting from the first IP, so we'll need to treat the IPs as
+ /* if a maximum connect attempts > 1 is set, enforce it directly */
+ if (set->max_connect_attempts > 1) {
+ return queue->connect_attempts >= set->max_connect_attempts;
+ }
+
+ /* otherwise, we'll always go through all the IPs. we don't necessarily
+ start connecting from the first IP, so we'll need to treat the IPs as
a ring buffer where we automatically wrap back to the first IP
when necessary. */
return (queue->ips_connect_idx + 1) % host->ips_count ==
@@ -244,8 +251,14 @@
}
}
}
- if (new_peer)
+ if (new_peer) {
+ http_client_queue_debug(queue, "Started new connection to %s%s",
+ http_client_peer_addr2str(addr), (addr->https_name == NULL ? "" :
+ t_strdup_printf(" (SSL=%s)", addr->https_name)));
+
array_append(&queue->pending_peers, &peer, 1);
+ queue->connect_attempts++;
+ }
/* start soft connect time-out (but only if we have another IP left) */
msecs = host->client->set.soft_connect_timeout_msecs;
@@ -265,6 +278,9 @@
queue->ips_connect_start_idx =
http_client_host_get_ip_idx(queue->host, &addr->ip);
+ /* reset attempt counter */
+ queue->connect_attempts = 0;
+
/* stop soft connect time-out */
if (queue->to_connect != NULL)
timeout_remove(&queue->to_connect);
@@ -343,6 +359,7 @@
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;
diff -r bf371c4fed6e -r 650629de6a73 src/lib-http/http-client.c
--- a/src/lib-http/http-client.c Wed Sep 10 13:39:37 2014 +0300
+++ b/src/lib-http/http-client.c Wed Sep 10 13:39:37 2014 +0300
@@ -120,6 +120,7 @@
client->set.max_pipelined_requests =
(set->max_pipelined_requests > 0 ? set->max_pipelined_requests : 1);
client->set.max_attempts = set->max_attempts;
+ client->set.max_connect_attempts = set->max_connect_attempts;
client->set.no_auto_redirect = set->no_auto_redirect;
client->set.no_ssl_tunnel = set->no_ssl_tunnel;
client->set.max_redirects = set->max_redirects;
diff -r bf371c4fed6e -r 650629de6a73 src/lib-http/http-client.h
--- a/src/lib-http/http-client.h Wed Sep 10 13:39:37 2014 +0300
+++ b/src/lib-http/http-client.h Wed Sep 10 13:39:37 2014 +0300
@@ -81,6 +81,17 @@
/* maximum number of attempts for a request */
unsigned int max_attempts;
+ /* maximum number of connection attempts to a host before all associated
+ requests fail.
+
+ if > 1, the maximum will be enforced across all IPs for that host,
+ meaning that IPs may be tried more than once eventually if the number
+ of IPs is smaller than the specified maximum attempts. If the number of IPs
+ is higher than the maximum attempts, not all IPs are tried. If <= 1, all
+ IPs are tried at most once.
+ */
+ unsigned int max_connect_attempts;
+
/* response header limits */
struct http_header_limits response_hdr_limits;
More information about the dovecot-cvs
mailing list