]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-client-connection - Improve overall logic in http_client_connection_st...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 12 Aug 2020 19:17:08 +0000 (21:17 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Thu, 27 Aug 2020 09:36:36 +0000 (11:36 +0200)
Make clear that idle_count < max when it is used.

src/lib-http/http-client-connection.c

index d4fecd8215ba222e51a0cebdb1bb868cd30e694f..fd59b7eec558ef74c3e8bbb2f9ba5aeda622bdce 100644 (file)
@@ -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));
        }