fix: race condition#8
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a test hook and an integration test that exercise concurrent signing to ensure the keyserver rejects conflicting votes at the same height by introducing controlled timing inside the validator's last-sign-state sync path. Changes
Sequence Diagram(s)sequenceDiagram
participant Test
participant PrivVal as PrivValidator
participant Raft
participant Disk
Test->>PrivVal: start concurrent Sign attempts (A and B)
PrivVal->>PrivVal: acquire lock
PrivVal->>PrivVal: compute new LastSignState
PrivVal->>PrivVal: call hook "before-raft" (if set)
PrivVal->>Raft: sync state via Raft
Raft-->>PrivVal: ack
PrivVal->>PrivVal: call hook "before-write" (if set)
alt conflict detected
PrivVal-->>Test: return RemoteSignerError (conflicting vote)
else no conflict
PrivVal->>Disk: write LastSignState
Disk-->>PrivVal: persist ack
PrivVal-->>Test: return success
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge base: Disabled due to 📒 Files selected for processing (1)
🔇 Additional comments (1)
✏️ Tip: You can disable this entire section by setting Comment |
There was a problem hiding this comment.
Pull request overview
This pull request fixes a race condition in the validator's state synchronization logic that could potentially allow conflicting signatures. The fix ensures that the entire state sync operation is atomic by holding the mutex for the duration of syncLastSignState() instead of releasing and re-acquiring it.
Changes:
- Modified locking in
syncLastSignState()to usedefer l.mu.Unlock()for the entire function duration instead of explicit lock/unlock pairs - Added a test hook (
syncLastSignStateHook) to enable testing of concurrent execution scenarios - Added new integration test
TestKeyserverRejectsConflictingVotesAtSameHeightto verify the race condition fix
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/keyserver/validator.go | Fixed race condition by holding mutex for entire syncLastSignState operation; added test hook for coordinating concurrent test scenarios |
| pkg/keyserver/signing_integration_test.go | Added integration test to verify conflicting votes at the same height are properly rejected under concurrent access |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary by CodeRabbit
Tests
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.