mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
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
eee6d622ed
commit
adebe3e723
2 changed files with 7 additions and 4 deletions
3
changelog/13146.txt
Normal file
3
changelog/13146.txt
Normal file
|
|
@ -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 a new issue