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:
sashass1315
2025-09-22 23:12:56 +03:00
committed by GitHub
parent 66ff6f70b8
commit 013b6b1d60
2 changed files with 6 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
### Fixed
- fix race in PriorityQueue.Pop by checking emptiness under write lock. (#15726)

View File

@@ -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")