From: Stephan Bosch Date: Thu, 23 Oct 2014 02:55:51 +0000 (+0300) Subject: lib-http: client: Implemented maximum for connection backoff time. X-Git-Tag: 2.2.15~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=94d1b08c9e20d637db568a3eab3dfc2b9e96e62a;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Implemented maximum for connection backoff time. Without a maximum, the backoff time grows exponentially to enormous values, because it isn't reset until the connection succeeds. This causes recovery from connection failures to become very slow. Current maximum is one minute. --- diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index 769b5350de..b70a2f7cc4 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -592,6 +592,8 @@ void http_client_peer_connection_failure(struct http_client_peer *peer, peer->backoff_time_msecs = set->connect_backoff_time_msecs; else peer->backoff_time_msecs *= 2; + if (peer->backoff_time_msecs > set->connect_backoff_max_time_msecs) + peer->backoff_time_msecs = set->connect_backoff_max_time_msecs; } if (pending > 1) { diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index a9dfe812be..4f2582a462 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -14,6 +14,7 @@ #define HTTP_CLIENT_CONTINUE_TIMEOUT_MSECS (1000*2) #define HTTP_CLIENT_DEFAULT_REQUEST_TIMEOUT_MSECS (1000*60*5) #define HTTP_CLIENT_DEFAULT_BACKOFF_TIME_MSECS (100) +#define HTTP_CLIENT_DEFAULT_BACKOFF_MAX_TIME_MSECS (1000*60) enum http_response_payload_type; diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index ad8d67ac95..1bda87eb01 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -125,6 +125,10 @@ struct http_client *http_client_init(const struct http_client_settings *set) set->connect_backoff_time_msecs == 0 ? HTTP_CLIENT_DEFAULT_BACKOFF_TIME_MSECS : set->connect_backoff_time_msecs; + client->set.connect_backoff_max_time_msecs = + set->connect_backoff_max_time_msecs == 0 ? + HTTP_CLIENT_DEFAULT_BACKOFF_MAX_TIME_MSECS : + set->connect_backoff_max_time_msecs; 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 --git a/src/lib-http/http-client.h b/src/lib-http/http-client.h index 46c100f6bb..74371bba97 100644 --- a/src/lib-http/http-client.h +++ b/src/lib-http/http-client.h @@ -95,6 +95,8 @@ struct http_client_settings { /* Initial backoff time; doubled at each connection failure */ unsigned int connect_backoff_time_msecs; + /* Maximum backoff time */ + unsigned int connect_backoff_max_time_msecs; /* response header limits */ struct http_header_limits response_hdr_limits;