fix(store): preserve final sync during shutdown - #1397
Draft
corylanou wants to merge 2 commits into
Draft
Conversation
PR Build Metrics✅ All clear — no issues detected
Binary Size
Dependency ChangesNo dependency changes. govulncheck OutputBuild Info
History (4 previous)
🤖 Updated on each push. |
corylanou
marked this pull request as draft
July 25, 2026 08:26
6 tasks
corylanou
force-pushed
the
fix/store-close-monitor-race
branch
2 times, most recently
from
July 27, 2026 17:41
687e053 to
81870c5
Compare
Cancel and join Store background monitors before closing managed databases. This prevents compaction and snapshot work from reading DB fields while DB.Close clears them.
Cancel Store monitors before database closure, but move their potentially unbounded wait after each database has completed its final WAL and replica sync. Let the caller context or second signal interrupt that post-flush wait. Track active snapshot readers under the DB executor semaphore and close and join their encoder goroutines before clearing database handles. This removes the remaining snapshotReader file-handle race even when a backend returns early or ignores cancellation.
corylanou
force-pushed
the
fix/store-close-monitor-race
branch
from
July 27, 2026 18:41
81870c5 to
c4a2240
Compare
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.
Description
Preserves the final database flush when Store-owned monitors are slow or ignore cancellation, while eliminating the snapshot encoder race with database handle cleanup.
Close(ctx)or the CLI second-signal channelDB.Close()clearsdb.fMotivation and Context
A full race sweep while validating PR #1396 caught
DB.Close()clearing database fields whilemonitorCompactionLevel()was still taking a snapshot. The initial fix moveds.wg.Wait()beforeDB.Close(), but cold review found that ordering introduced a durability regression: file fsync and SFTP operations can ignore cancellation, so shutdown could block before the final WAL-to-LTX and replica sync. A second signal could not interrupt that wait.The review also found that waiting for the Store monitor did not completely eliminate the original race.
snapshotReaderlaunches an encoder goroutine that was not joined when a backend returned early; the monitor could finish while that encoder still useddb.f.Both major findings and the test-coverage finding were confirmed. The revised design does not make final-flush correctness depend on a backend monitor stopping:
DB.Close()acquires the DB execution semaphore, closes all registered snapshot pipes, and joins their encoders.This deliberately avoids placing an unbounded backend wait in front of the final flush. Discovered while validating #1396.
How Has This Been Tested?
The regressions fail on the previous PR head
4364eab:Snapshotreturn while its encoder still holds the checkpoint lockStore.Close()from reaching the final syncThe replacement Store regression runs through the real snapshot monitor and
snapshotReader, leaves the backend blocked after cancellation, writes pending WAL data, and verifies that shutdown still advances both the local and replica TXIDs before a second signal interrupts the remaining monitor wait.The low-, high-, and burst-volume behavioral profiles all passed shutdown, restoration, and integrity validation.
Types of changes
Checklist
go fmt,go vet)go test ./...)