diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index e1b6d0633..c5cd3c8fe 100644 --- a/include/haproxy/stick_table.h +++ b/include/haproxy/stick_table.h @@ -198,15 +198,22 @@ static inline int __stksess_kill_if_expired(struct stktable *t, struct stksess * static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *ts, int decrefcnt) { - HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); - if (decrefcnt) - ts->ref_cnt--; + if (t->expire != TICK_ETERNITY && tick_is_expired(ts->expire, now_ms)) { + HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); + if (decrefcnt) + ts->ref_cnt--; - if (t->expire != TICK_ETERNITY && tick_is_expired(ts->expire, now_ms)) __stksess_kill_if_expired(t, ts); - - HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); + HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); + } + else { + if (decrefcnt) { + HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); + HA_ATOMIC_DEC(&ts->ref_cnt); + HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); + } + } } /* sets the stick counter's entry pointer */ diff --git a/src/stick_table.c b/src/stick_table.c index b5e04d829..92f662dfb 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -103,9 +103,9 @@ void stksess_free(struct stktable *t, struct stksess *ts) dict_entry_unref(&server_key_dict, stktable_data_cast(data, std_t_dict)); stktable_data_cast(data, std_t_dict) = NULL; } - HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock); + HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->lock); __stksess_free(t, ts); - HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock); + HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->lock); } /*