mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 20:43:57 -05:00
fix: race in PriorityQueue.Pop by checking emptiness under write lock (#15726)
* fix: race in PriorityQueue.Pop by checking emptiness under write lock * Create sashass1315_fix-priority-queue-pop-lock-race * Update changelog/sashass1315_fix-priority-queue-pop-lock-race Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Move changelog/sashass1315_fix-priority-queue-pop-lock-race to changelog/sashass1315_fix-priority-queue-pop-lock-race.md * Fix bullet in changelog --------- Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- fix race in PriorityQueue.Pop by checking emptiness under write lock. (#15726)
|
||||
@@ -86,13 +86,13 @@ func (pq *PriorityQueue) Len() int {
|
||||
// wrapper/convenience method that calls heap.Pop, so consumers do not need to
|
||||
// invoke heap functions directly
|
||||
func (pq *PriorityQueue) Pop() (*Item, error) {
|
||||
if pq.Len() == 0 {
|
||||
return nil, ErrEmpty
|
||||
}
|
||||
|
||||
pq.lock.Lock()
|
||||
defer pq.lock.Unlock()
|
||||
|
||||
if pq.data.Len() == 0 {
|
||||
return nil, ErrEmpty
|
||||
}
|
||||
|
||||
item, ok := heap.Pop(&pq.data).(*Item)
|
||||
if !ok {
|
||||
return nil, errors.New("unknown type")
|
||||
|
||||
Reference in New Issue
Block a user