From f2fc1fda804962224664e3a23c8a9ed88e4076b6 Mon Sep 17 00:00:00 2001 From: Emeric Brun Date: Thu, 2 Nov 2017 17:32:43 +0100 Subject: [PATCH] BUG/MINOR: freq: fix infinite loop on freq_ctr_period. Using peers or stick table we could update an freq_ctr using a tick value with the first bit set but this bit is reserved for lock since multithreading support. --- src/peers.c | 7 ++++++- src/stick_table.c | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/peers.c b/src/peers.c index 9419afe4e..4819937ce 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1312,7 +1312,12 @@ switchstate: case STD_T_FRQP: { struct freq_ctr_period data; - data.curr_tick = tick_add(now_ms, -intdecode(&msg_cur, msg_end)); + /* First bit is reserved for the freq_ctr_period lock + Note: here we're still protected by the stksess lock + so we don't need to update the update the freq_ctr_period + using its internal lock */ + + data.curr_tick = tick_add(now_ms, -intdecode(&msg_cur, msg_end)) & ~0x1; if (!msg_cur) { /* malformed message */ RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock); diff --git a/src/stick_table.c b/src/stick_table.c index 55a1fff8d..0e84102f6 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -2968,7 +2968,11 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args) * push measures without having to update them too often. */ frqp = &stktable_data_cast(ptr, std_t_frqp); - frqp->curr_tick = now_ms; + /* First bit is reserved for the freq_ctr_period lock + Note: here we're still protected by the stksess lock + so we don't need to update the update the freq_ctr_period + using its internal lock */ + frqp->curr_tick = now_ms & ~0x1; frqp->prev_ctr = 0; frqp->curr_ctr = value; break;