Skip to content

Commit

Permalink
fix(halo/app): fix readiness deadlock (#2558)
Browse files Browse the repository at this point in the history
Avoid re-entrant `sync.RWMutex` read locking.

issue: none
  • Loading branch information
corverroos authored Nov 25, 2024
1 parent 6c232a8 commit ea783ab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion halo/app/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func (r *readinessStatus) ready() bool {
r.mu.RLock()
defer r.mu.RUnlock()

return r.readyUnsafe()
}

// readyUnsafe is the same as ready but without locking.
// It is unsafe since it assumes the lock is held.
func (r *readinessStatus) readyUnsafe() bool {
return r.ConsensusSynced &&
r.ConsensusP2PPeers > 0 &&
r.ConsensusHeight > 0 &&
Expand All @@ -46,7 +52,7 @@ func (r *readinessStatus) serialize(w io.Writer) (bool, error) {
return false, errors.Wrap(err, "readiness status serialization")
}

return r.ready(), nil
return r.readyUnsafe(), nil
}

// setConsensusSynced sets the flag indicating the consensus is synced.
Expand Down

0 comments on commit ea783ab

Please sign in to comment.