Skip to content

Call OnRemove after the shard lock is released - #442

Open
SashaMIT wants to merge 1 commit into
allegro:mainfrom
SashaMIT:fix/onremove-reinsert
Open

SashaMIT wants to merge 1 commit into
allegro:mainfrom
SashaMIT:fix/onremove-reinsert

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 12, 2026 •

Copy link
Copy Markdown

Fixes #411.

OnRemove, OnRemoveWithReason, and OnRemoveWithMetadata ran while the shard lock was held. Reinserting the removed key from the callback called Set on that same shard, which locked it again, so the call never returned and later evictions never ran.

The key and value are copied, the lock is released, and then the callback runs. Per-key stats are removed after the callback so OnRemoveWithMetadata still sees the request count.

TestOnRemoveReinsertDoesNotStopLaterCallbacks reinserts "a" from the callback and then sets "c". With the callback under the lock, that second set does not return. After the callback is moved out, both removals are reported.

A cache that refreshes an entry from this callback stops reporting removals on that shard.

The callback ran while the shard lock was held. Reinserting the
removed key from OnRemove locked the same shard again and later
evictions never ran.

Signed-off-by: Sasha Mitchell <sash.t.mitchell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The callback function OnRemoveWithReason suddenly stops being called, even though there is new data being written

1 participant