sdk/queue: move lock before checking queue length (#13146)
* sdk/queue: move lock before checking queue length * Add changelog
This commit is contained in:
parent
f39f1ce8de
commit
660a7be134
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
sdk/queue: move lock before length check to prevent panics.
|
||||
```
|
|
@ -85,13 +85,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 := heap.Pop(&pq.data).(*Item)
|
||||
delete(pq.dataMap, item.Key)
|
||||
return item, nil
|
||||
|
|
Loading…
Reference in New Issue