From dbda31939dd3c775adb48ceeadbda89e42a25390 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Sun, 22 Mar 2020 19:59:52 +0100 Subject: [PATCH] BUG/MINOR: connections: Set idle_time before adding to idle list. 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/proto/server.h b/include/proto/server.h index 6eb45153a..575e92281 100644 --- a/include/proto/server.h +++ b/include/proto/server.h @@ -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);