redis_store: hold subscribed_keys write lock across receiver drop#2353
Open
amankrx wants to merge 2 commits into
Open
redis_store: hold subscribed_keys write lock across receiver drop#2353amankrx wants to merge 2 commits into
amankrx wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RedisSubscription::Droppreviously dropped thewatch::Receiverbefore taking thesubscribed_keyswrite lock, then decided whether to remove the publisher entry based onreceiver_count() == 0. Two concurrent drops on subscriptions sharing a publisher (e.g. multipleWaitExecutionclients on the same operation_id) could both decrement their counts before either took the lock, then race for it: the loser saw the entry already removed and emitted a spurious "Key … was not found in subscribed keys" error. Worse, if a freshsubscribe(same_key)interleaved between the two drops, the second drop could remove the freshly-inserted publisher and silently strand its subscribers.Acquire the write lock first, evaluate "count == 1 with my receiver still alive", remove the entry under the lock if so, then drop the receiver. The lock now serialises both the count read and the map mutation, closing both race windows. Demote the absence log from
error!towarn!: with the fix, that path now indicates a genuine unexpected mutation outside the lock, not the race noise.Description
Please include a summary of the changes and the related issue. Please also
include relevant motivation and context.
Fixes # (issue)
Type of change
Please delete options that aren't relevant.
How Has This Been Tested?
Adds 4 regression tests covering single-drop silence, drop-one-of-two preserving the publisher, 200-iteration concurrent-drop race, and resubscribe-after-drop creating a fresh publisher.
Checklist
bazel test //...passes locallygit amendsee some docsThis change is