db/snapshotsync: fix crash due to double close of decompressor #21545
Merged
Conversation
…List closeWhatNotInList closed dirty segments that were not in the canonical on-disk list without checking their refcount, so it could close a segment (nilling its decompressor) while a live View/RoTx still held it. After a merge, TypedSegments->NoOverlaps drops the merged-away sub-segments from the list even though their files remain on disk; a concurrent OpenFolder then closed those subsumed segments out from under the merge's own View, and the View's later closeAndRemoveFiles hit FilePath() on the nil decompressor and crashed. Skip refcount-held segments in closeWhatNotInList; they are reaped on a later pass once the reader releases them. View/BeginRo stays lock-free.
1fa270f to
c2eba3d
Compare
AskAlexSharov
approved these changes
Jun 1, 2026
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.
Problem
dirtySegment.close()(closes seg and idx) can happen on subsegments once some collation doesOpenFolder, which usesTypedSegmentswhich closes the subsegments.closeWhatNotInList-- merge calls this and can crash because of close earlier.Fix
In
closeWhatNotInList, skip segments withrefcount > 0: a live reader still references them, so closing now would invalidate that reader. They are reaped on a later pass once the reader releases them (closeWhatNotInListalready runs on everyOpenFolder).View/BeginRostays lock-free (#20490) — the fix is purely in the close path.Test
TestCloseWhatNotInListVsLiveViewDoesNotCrashreproduces the crash deterministically (puresnapshotsync, no merge machinery): it builds sub-segments, opens aViewover them, drops a covering merged file on disk, reopens (soNoOverlapsremoves the subs from the list), and assertsView.Closedoes not crash. It fails before this change and passes after.