From: zeripath Date: Sat, 13 Feb 2021 19:02:09 +0000 (+0000) Subject: Prevent race in PersistableChannelUniqueQueue.Has (#14651) X-Git-Tag: v1.15.0-dev~187 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b3c2e23cbbfc6386f0d35e252051f9f74f548f98;p=gitea.git Prevent race in PersistableChannelUniqueQueue.Has (#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 #14311 Signed-off-by: Andrew Thornton --- diff --git a/modules/queue/unique_queue_disk_channel.go b/modules/queue/unique_queue_disk_channel.go index 71049f3259..4a69b43eae 100644 --- a/modules/queue/unique_queue_disk_channel.go +++ b/modules/queue/unique_queue_disk_channel.go @@ -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) }