]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: connections: Set idle_time before adding to idle list.
authorOlivier Houchard <cognet@ci0.org>
Sun, 22 Mar 2020 18:59:52 +0000 (19:59 +0100)
committerOlivier Houchard <cognet@ci0.org>
Sun, 22 Mar 2020 19:05:59 +0000 (20:05 +0100)
In srv_add_to_idle_list(), make sure we set the idle_time before we add
the connection to an idle list, not after, otherwise another thread may
grab it, set the idle_time to 0, only to have the original thread set it
back to now_ms.
This may have an impact, as in conn_free() we check idle_time to decide
if we should decrement the idle connection counters for the server.

include/proto/server.h

index 6eb45153add9632013411cd48eddff5ac1f744f6..575e922811bd401b27a807b7eefe5f4b5736a354 100644 (file)
@@ -262,6 +262,7 @@ static inline int srv_add_to_idle_list(struct server *srv, struct connection *co
                        return 0;
                }
                MT_LIST_DEL(&conn->list);
+               conn->idle_time = now_ms;
                if (is_safe) {
                        conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;
                        MT_LIST_ADDQ(&srv->safe_conns[tid], (struct mt_list *)&conn->list);
@@ -273,7 +274,6 @@ static inline int srv_add_to_idle_list(struct server *srv, struct connection *co
                }
                _HA_ATOMIC_ADD(&srv->curr_idle_thr[tid], 1);
 
-               conn->idle_time = now_ms;
                __ha_barrier_full();
                if ((volatile void *)srv->idle_node.node.leaf_p == NULL) {
                        HA_SPIN_LOCK(OTHER_LOCK, &idle_conn_srv_lock);