From: Stephan Bosch Date: Wed, 12 Aug 2020 19:17:08 +0000 (+0200) Subject: lib-http: http-client-connection - Improve overall logic in http_client_connection_st... X-Git-Tag: 2.3.13~271 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d49e42f9a3abcbfb7ba8b113bd5f800c4019856;p=thirdparty%2Fdovecot%2Fcore.git lib-http: http-client-connection - Improve overall logic in http_client_connection_start_idle_timeout(). Make clear that idle_count < max when it is used. --- diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index d4fecd8215..fd59b7eec5 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -429,7 +429,7 @@ http_client_connection_start_idle_timeout(struct http_client_connection *conn) http_client_connection_get_settings(conn); struct http_client_peer_pool *ppool = conn->ppool; struct http_client_peer_shared *pshared = ppool->peer; - unsigned int timeout, count, max; + unsigned int timeout, count, idle_count, max; i_assert(conn->to_idle == NULL); @@ -437,20 +437,19 @@ http_client_connection_start_idle_timeout(struct http_client_connection *conn) return UINT_MAX; count = array_count(&ppool->conns); - i_assert(count > 0); + idle_count = array_count(&ppool->idle_conns); max = http_client_peer_shared_max_connections(pshared); + i_assert(count > 0); + i_assert(count >= idle_count + 1); i_assert(max > 0); /* Set timeout for this connection */ - if (count > max) { + if (count > max || idle_count >= max) { /* Instant death for (urgent) connections above limit */ timeout = 0; } else { - unsigned int idle_count = array_count(&ppool->idle_conns); - /* Kill duplicate connections quicker; linearly based on the number of connections */ - i_assert(count >= idle_count + 1); timeout = ((max - idle_count) * (set->max_idle_time_msecs / max)); }