From: Willy Tarreau Date: Tue, 16 Feb 2021 17:08:12 +0000 (+0100) Subject: BUG/MINOR: session: atomically increment the tracked sessions counter X-Git-Tag: v2.1.12~39 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=88131dc6f8aecbd26db051343ad6f9dcf4496348;p=haproxy-2.1.git BUG/MINOR: session: atomically increment the tracked sessions counter In session_count_new() the tracked counter was still incremented with a "++" outside of any lock, resulting in occasional slightly off values such as the following: # table: foo, type: string, size:1000, used:1 0xb2a398: key=127.1.2.3 use=0 exp=86398318 sess_cnt=999959 http_req_cnt=1000004 Now with the correct atomic increment: # table: foo, type: string, size:1000, used:1 0x7f82a4026d38: key=127.1.2.3 use=0 exp=86399294 sess_cnt=1000004 http_req_cnt=1000004 This can be backported to 1.8. (cherry picked from commit 9805859f245f4f59fc3baa098cb349786e21aaba) Signed-off-by: Christopher Faulet (cherry picked from commit 86eb8369d3c584631e6f4f93a2e2cfcba945bee6) Signed-off-by: Christopher Faulet (cherry picked from commit e78daa425262e64faf520784e318eb2e35e819e7) Signed-off-by: Christopher Faulet --- diff --git a/src/session.c b/src/session.c index 111fc61..de8a4f3 100644 --- a/src/session.c +++ b/src/session.c @@ -123,7 +123,7 @@ static void session_count_new(struct session *sess) ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); if (ptr) - stktable_data_cast(ptr, sess_cnt)++; + HA_ATOMIC_ADD(&stktable_data_cast(ptr, sess_cnt), 1); ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); if (ptr)