Skip to content

Commit 95614d0

Browse files
CCF [bot]eddyashton
CCF [bot]
andauthored
[release/5.x] Cherry pick: Delay lock taking slightly (#6627) (#6635)
Co-authored-by: Eddy Ashton <[email protected]>
1 parent 4873a6c commit 95614d0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/node/history.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ namespace ccf
612612
bool init_from_snapshot(
613613
const std::vector<uint8_t>& hash_at_snapshot) override
614614
{
615-
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
616615
// The history can be initialised after a snapshot has been applied by
617616
// deserialising the tree in the signatures table and then applying the
618617
// hash of the transaction at which the snapshot was taken
@@ -626,6 +625,10 @@ namespace ccf
626625
return false;
627626
}
628627

628+
// Delay taking this lock until _after_ the read above, to avoid lock
629+
// inversions
630+
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
631+
629632
CCF_ASSERT_FMT(
630633
!replicated_state_tree.in_range(1),
631634
"Tree is not empty before initialising from snapshot");

0 commit comments

Comments
 (0)