Unverified Commit adebe3e7 authored by Jason O'Donnell's avatar Jason O'Donnell Committed by GitHub
Browse files

sdk/queue: move lock before checking queue length (#13146)

* sdk/queue: move lock before checking queue length

* Add changelog
Showing with 7 additions and 4 deletions
+7 -4
```release-note:bug
sdk/queue: move lock before length check to prevent panics.
```
\ No newline at end of file
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment