Skip to content

Commit

Permalink
Fix potential data race: Lock all KV maps during apply_changes, eve…
Browse files Browse the repository at this point in the history
…n those which are read-only (microsoft#6866)
  • Loading branch information
eddyashton authored Feb 28, 2025
1 parent 7fec395 commit da4d63e
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/kv/apply_changes.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,8 @@ namespace ccf::kv

for (auto it = changes.begin(); it != changes.end(); ++it)
{
bool changeset_has_writes = it->second.changeset->has_writes();
if (changeset_has_writes)
{
has_writes = true;
}
if (changeset_has_writes || track_read_versions)
{
it->second.map->lock();
}
has_writes |= it->second.changeset->has_writes();
it->second.map->lock();
}

bool ok = true;
Expand Down Expand Up @@ -177,10 +170,7 @@ namespace ccf::kv

for (auto it = changes.begin(); it != changes.end(); ++it)
{
if (it->second.changeset->has_writes() || track_read_versions)
{
it->second.map->unlock();
}
it->second.map->unlock();
}

if (!ok)
Expand Down

0 comments on commit da4d63e

Please sign in to comment.