]> source.dussan.org Git - gitea.git/commitdiff
Prevent race in PersistableChannelUniqueQueue.Has (#14651)
authorzeripath <art27@cantab.net>
Sat, 13 Feb 2021 19:02:09 +0000 (19:02 +0000)
committerGitHub <noreply@github.com>
Sat, 13 Feb 2021 19:02:09 +0000 (20:02 +0100)
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 <art27@cantab.net>
modules/queue/unique_queue_disk_channel.go

index 71049f3259aa9b315f47f04fa9ec63bfeb80227b..4a69b43eae0e3e169dfe9b089e155af3c51a1059 100644 (file)
@@ -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)
 }