]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-client-connection - Make idle timeout calculation more robust.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 12 Aug 2020 19:33:08 +0000 (21:33 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Thu, 27 Aug 2020 09:36:36 +0000 (11:36 +0200)
src/lib-http/http-client-connection.c
src/lib-http/http-client-private.h

index 1a510495460f06f98183ba18b5e0bd4aa23355ec..0bd58162820b05626c0ae58c374be5e02ed2b31b 100644 (file)
@@ -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(
index ccc41ed91afc9608acc9e8500fb116c58ee80b3e..86b1d96202a6b8591483107880f9ade8844093ba 100644 (file)
@@ -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