Skip to content

Commit

Permalink
Prevent race in PersistableChannelUniqueQueue.Has (go-gitea#14651)
Browse files Browse the repository at this point in the history
Backport go-gitea#14651

There is potentially a race with a slow starting internal
queue causing a NPE if Has is checked before the internal
queue has been setup.

This PR adds a lock on the Has() fn.

Fix go-gitea#14311

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Feb 13, 2021
1 parent a1b74c5 commit 58470a6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/queue/unique_queue_disk_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func (q *PersistableChannelUniqueQueue) Has(data Data) (bool, error) {
if err != nil || has {
return has, err
}
q.lock.Lock()
defer q.lock.Unlock()
if q.internal == nil {
return false, nil
}
return q.internal.(UniqueQueue).Has(data)
}

Expand Down

0 comments on commit 58470a6

Please sign in to comment.