From f305cffcaf61ecfba7d5e6c28492ca640da1c98d Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 14 Feb 2021 00:50:50 +0000 Subject: [PATCH] Prevent race in PersistableChannelUniqueQueue.Has (#14651) (#14676) Backport #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 Co-authored-by: 6543 <6543@obermui.de> --- modules/queue/unique_queue_disk_channel.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/queue/unique_queue_disk_channel.go b/modules/queue/unique_queue_disk_channel.go index 71049f325..4a69b43ea 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) }