[InMemory] Fixed deadlock - #559
Merged
Merged
Conversation
Interesting bug found by accident when trying to benchmark in memory: 1. Client calls `Witness.Update`, which calls `Persistence.Update`. The in-memory persistence acquires a write lock on its global mutex to safely update the checkpoint. 2. `Persistence.Update` calls the callback function provided to perform consistency checks. 3. To verify the signature on the previous checkpoint, the callback needs the log's public key. It calls `Persistence.Log`, which attempts to acquire a read lock on the same global mutex 4. Deadlock! This introduces a sync.Map for the logs (which are largely intialized up-front), and uses a mutex for the checkpoint state.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #559 +/- ##
==========================================
+ Coverage 24.35% 24.63% +0.28%
==========================================
Files 27 27
Lines 2012 2005 -7
==========================================
+ Hits 490 494 +4
+ Misses 1417 1406 -11
Partials 105 105 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AlCutter
approved these changes
Jun 16, 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.
Interesting bug found by accident when trying to benchmark in memory:
Witness.Update, which callsPersistence.Update. The in-memory persistence acquires a write lock on its global mutex to safely update the checkpoint.Persistence.Updatecalls the callback function provided to perform consistency checks.Persistence.Log, which attempts to acquire a read lock on the same global mutexThis introduces a sync.Map for the logs (which are largely intialized up-front), and uses a mutex for the checkpoint state.