diff --git a/src/stick_table.c b/src/stick_table.c index c9faa56a8..240f10c75 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -927,10 +927,9 @@ struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts) HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &table->shards[shard].sh_lock); return ts; } - ts = nts; /* let's increment it before switching to exclusive */ - HA_ATOMIC_INC(&ts->ref_cnt); + HA_ATOMIC_INC(&nts->ref_cnt); if (HA_RWLOCK_TRYRDTOSK(STK_TABLE_LOCK, &table->shards[shard].sh_lock) != 0) { /* upgrade to seek lock failed, let's drop and take */ @@ -942,10 +941,15 @@ struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts) /* now we're write-locked */ - __stktable_store(table, ts, shard); + ts = __stktable_store(table, nts, shard); + if (ts != nts) { + HA_ATOMIC_DEC(&nts->ref_cnt); + HA_ATOMIC_INC(&ts->ref_cnt); + } HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &table->shards[shard].sh_lock); - stktable_requeue_exp(table, ts); + if (ts == nts) + stktable_requeue_exp(table, ts); return ts; }