Skip to content

Introduce mutex locks in MirBFT node and add concurrency tests#24

Open
saiashok0981 wants to merge 1 commit into
BiniWorld:mainfrom
saiashok0981:mirbft-data-race-fix
Open

Introduce mutex locks in MirBFT node and add concurrency tests#24
saiashok0981 wants to merge 1 commit into
BiniWorld:mainfrom
saiashok0981:mirbft-data-race-fix

Conversation

@saiashok0981

Copy link
Copy Markdown

Issue 2: Concurrent Map Writes and Missing Mutex Synchronization in MirBFT Node
Issue Description
Title: Bug: Data race and concurrent map writes in MirBFT Node methods

Description: The MirBFT struct defined in candidates/siddhantprateek/mirbft/mirbft-sample/main.go includes a Mutex sync.Mutex field, but it is never locked or unlocked in any of its methods. Methods such as Propose, ProcessProposal, and Commit read and write to several shared nested map variables:

mb.Pending
mb.Committed
mb.Received
Under concurrent scenarios (e.g., multiple nodes receiving messages or processing proposals concurrently), this results in a data race and triggers a runtime panic: fatal error: concurrent map writes.

Expected Behavior: All read and write accesses to shared maps (Pending, Committed, Received) inside the MirBFT instance must be synchronized using mb.Mutex to ensure thread-safety.

Pull Request Description
Title: Introduce mutex locks in MirBFT node and add concurrency tests

Branch: mirbft-data-race-fix

Description of Changes:

Thread-Safety: Added proper mb.Mutex.Lock() and mb.Mutex.Unlock() calls to Propose, ProcessProposal, and Commit methods around operations mutating or reading the shared maps.
Deadlock Avoidance: Structured the critical sections carefully, releasing locks before calling sibling methods (like calling Commit from ProcessProposal) or running simulated side-effects (SendMessage, ExecuteRequest) to avoid recursive deadlocks and reduce lock contention.
Added Concurrency Tests: Created a new test file candidates/siddhantprateek/mirbft/mirbft-sample/main_test.go containing concurrent tests TestMirBFTConcurrency and TestMirBFTProcessProposalConcurrency to verify thread-safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant