fix: race condition in stateMap access during concurrent replication#263
fix: race condition in stateMap access during concurrent replication#263remo-lab wants to merge 1 commit intocontainer-registry:mainfrom
Conversation
📝 WalkthroughWalkthroughReworks concurrency in Changes
Sequence DiagramsequenceDiagram
participant Main as Main Process
participant Mutex as Struct Mutex
participant Snapshot as State Snapshot
participant Fetcher as State Fetcher Goroutines
participant StateMap as Live stateMap
Main->>Mutex: lock
Mutex->>StateMap: read entries & copy
Mutex->>Snapshot: create snapshot
Main->>Mutex: unlock
Main->>Fetcher: launch goroutines with snapshot entries
Fetcher->>Snapshot: read entry (read-only)
Fetcher->>Fetcher: processStateEntry (fetch, process, decide delete/replicate)
Fetcher->>Main: send StateFetcherResult
Main->>Mutex: lock
Mutex->>StateMap: locate entry by URL and update via updateStateMapEntry
Main->>Mutex: unlock
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codacy's Analysis Summary0 new issue (≤ 0 issue) Review Pull Request in Codacy →
|
c5f46a8 to
4719082
Compare
Signed-off-by: remo-lab <remopanda7@gmail.com>
4719082 to
309ccbd
Compare
Summary
Fixes a critical race condition in
FetchAndReplicateStateProcess.Execute()where concurrent goroutines access and mutatef.stateMapwithout proper synchronization.Problem
f.stateMapwithout holding any lockf.stateMap[index]without lock during slice mutationImpact: Panic (index out of bounds) or silent data corruption when Ground Control changes group assignments.
Solution
f.muFiles Changed
Summary by cubic
Fixes a race condition in concurrent replication by synchronizing stateMap access and processing a locked snapshot in goroutines. Prevents panics and data corruption when group assignments change.
Written for commit 309ccbd. Summary will update on new commits.
Summary by CodeRabbit
Refactor
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.