]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-client-connection - Handle infinite idle timeout consistently.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 12 Aug 2020 18:35:46 +0000 (20:35 +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

index 5d4339b4ac6c0b0eba35c08a206ebfc24003b41a..9e73f844d6f306eec91163319a6bce4869ac4080 100644 (file)
@@ -433,6 +433,9 @@ http_client_connection_start_idle_timeout(struct http_client_connection *conn)
 
        i_assert(conn->to_idle == NULL);
 
+       if (set->max_idle_time_msecs == 0)
+               return UINT_MAX;
+
        count = array_count(&ppool->conns);
        i_assert(count > 0);
        max = http_client_peer_shared_max_connections(pshared);
@@ -474,9 +477,13 @@ void http_client_connection_lost_peer(struct http_client_connection *conn)
 
                timeout = http_client_connection_start_idle_timeout(conn);
 
-               e_debug(conn->event,
-                       "Lost peer; going idle (timeout = %u msecs)",
-                       timeout);
+               if (timeout == UINT_MAX)
+                       e_debug(conn->event, "Lost peer; going idle");
+               else {
+                       e_debug(conn->event,
+                               "Lost peer; going idle (timeout = %u msecs)",
+                               timeout);
+               }
 
                conn->idle = TRUE;
                array_push_back(&ppool->idle_conns, &conn);
@@ -491,8 +498,6 @@ void http_client_connection_check_idle(struct http_client_connection *conn)
 {
        struct http_client_peer *peer;
        struct http_client_peer_pool *ppool = conn->ppool;
-       struct http_client *client;
-       const struct http_client_settings *set;
 
        peer = conn->peer;
        if (peer == NULL) {
@@ -505,19 +510,13 @@ void http_client_connection_check_idle(struct http_client_connection *conn)
                return;
        }
 
-       client = peer->client;
-       set = &client->set;
-
        if (conn->connected &&
            array_is_created(&conn->request_wait_list) &&
            array_count(&conn->request_wait_list) == 0 &&
-           !conn->in_req_callback && conn->incoming_payload == NULL &&
-           set->max_idle_time_msecs > 0) {
+           !conn->in_req_callback && conn->incoming_payload == NULL) {
+               struct http_client *client = peer->client;
                unsigned int timeout;
 
-               i_assert(peer != NULL);
-               client = peer->client;
-
                i_assert(conn->to_requests == NULL);
 
                if (client->waiting)
@@ -525,9 +524,14 @@ void http_client_connection_check_idle(struct http_client_connection *conn)
 
                timeout = http_client_connection_start_idle_timeout(conn);
 
-               e_debug(conn->event,
-                       "No more requests queued; going idle "
-                       "(timeout = %u msecs)", timeout);
+               if (timeout == UINT_MAX) {
+                       e_debug(conn->event,
+                               "No more requests queued; going idle");
+               } else {
+                       e_debug(conn->event,
+                               "No more requests queued; going idle "
+                               "(timeout = %u msecs)", timeout);
+               }
 
                conn->idle = TRUE;
                array_push_back(&ppool->idle_conns, &conn);