From: Stephan Bosch Date: Wed, 12 Aug 2020 19:33:08 +0000 (+0200) Subject: lib-http: http-client-connection - Make idle timeout calculation more robust. X-Git-Tag: 2.3.13~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9751e9b2248a27bde73741417ab9b397d28e9f5;p=thirdparty%2Fdovecot%2Fcore.git lib-http: http-client-connection - Make idle timeout calculation more robust. --- diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index 1a51049546..0bd5816282 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -452,10 +452,16 @@ http_client_connection_start_idle_timeout(struct http_client_connection *conn) /* Instant death for (urgent) connections above limit */ timeout = 0; } else { + unsigned int idle_slots_avail; + double idle_time_per_slot; + /* Kill duplicate connections quicker; linearly based on the number of connections */ - timeout = ((max - idle_count) * - (set->max_idle_time_msecs / max)); + idle_slots_avail = max - idle_count; + idle_time_per_slot = (double)set->max_idle_time_msecs / max; + timeout = (unsigned int)(idle_time_per_slot * idle_slots_avail); + if (timeout < HTTP_CLIENT_MIN_IDLE_TIMEOUT_MSECS) + timeout = HTTP_CLIENT_MIN_IDLE_TIMEOUT_MSECS; } conn->to_idle = timeout_add_to( diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index ccc41ed91a..86b1d96202 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -16,6 +16,7 @@ #define HTTP_CLIENT_DEFAULT_BACKOFF_TIME_MSECS (100) #define HTTP_CLIENT_DEFAULT_BACKOFF_MAX_TIME_MSECS (1000*60) #define HTTP_CLIENT_DEFAULT_DNS_TTL_MSECS (1000*60*30) +#define HTTP_CLIENT_MIN_IDLE_TIMEOUT_MSECS 50 /* * Types