Fix race when publishing deserialised KV maps#8064
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a TSAN-detected data race in CCF’s KV Store by ensuring the map-set (Store::maps) is not mutated concurrently with map lookups when committing deserialised transactions that publish newly created dynamic maps.
Changes:
- Hold
maps_lockduringStore::commit_deserialised()whennew_mapsis non-empty, preventing concurrentadd_dynamic_map()mutations ofStore::mapswhile readers callget_map_internal(). - Add a concurrent regression test that applies serialised dynamic-map creations while multiple reader threads repeatedly look up a (missing) map name to exercise the previously-racy access pattern under TSAN.
Custom instructions used:
.github/copilot-instructions.md.github/instructions/reviewing.instructions.md
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/kv/store.h | Conditionally acquires maps_lock across apply_changes() during deserialised commits when dynamic maps may be published. |
| src/kv/test/kv_dynamic_tables.cpp | Adds a TSAN-focused concurrency regression test covering concurrent map publication vs. map lookup. |
cjen1-msft
approved these changes
Jul 20, 2026
achamayou
enabled auto-merge (squash)
July 20, 2026 19:52
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
Background
fill_maps()discovers missing maps while holdingmaps_lock, but releases that lock beforecommit_deserialised()callsapply_changes(). The latter publishes each map throughadd_dynamic_map(), mutatingStore::mapsconcurrently with readers inget_map_internal().The new regression reproduces 4 TSAN warnings before the fix, with the same
get_map_internal()/add_dynamic_map()access pair seen while investigating #8002. The race predates that PR.Testing
kv_test: passedkv_test: passed with no sanitizer warnings