fix: re-validate compaction boundary to prevent missed deletion events in watch - #7
Open
Kasuki354 wants to merge 1 commit into
Open
fix: re-validate compaction boundary to prevent missed deletion events in watch#7Kasuki354 wants to merge 1 commit into
Kasuki354 wants to merge 1 commit into
Conversation
… prevent missed deletion events The race condition occurred when a watch was created with startRev close to the compaction boundary. If compaction advanced between the boundary check and the watcher registration, the watcher could be added to the unsynced group with a minRev that had already been compacted, causing it to silently miss deletion events. Fix: 1. In watch(): after adding watcher to unsynced, re-validate minRev against compactMainRev. If compaction advanced, cancel the watcher immediately with ErrCompacted. 2. In syncWatchers(): re-check compactMainRev for every unsynced watcher before any data read, ensuring no watcher reads compacted data. 3. Both checks happen under s.Mu + s.store.Mu locks, ensuring atomicity. Resolves morriganreza973#5
|
😅 Unfortunately there are no rewards left to claim in this issue! |
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.
Summary
Fixes issue #5: Race condition where Watch misses deletion event near compaction boundary.
Root Cause
In watch(), the compaction boundary check (startRev <= compactMainRev) and the watcher registration happen under both s.Mu and s.store.Mu locks. However, there is an edge case: if the watcher is added to the unsynced group with a minRev that is valid at check time, but compaction advances before syncWatchers() runs, the watcher could read compacted data and miss the deletion event.
Fix
watch(): After adding watcher to unsynced, re-validate minRev against compactMainRev. If compaction advanced, cancel the watcher immediately with ErrCompacted.
syncWatchers(): Re-check compactMainRev for every unsynced watcher before any data read attempt. If minRev <= compactMainRev, cancel with ErrCompacted.
Both checks happen under s.Mu + s.store.Mu locks, ensuring atomicity with compaction.
/claim #5