Skip to content

Commit a8d54d7

Browse files
committed
fix(coderd/database/pubsub): prevent listeners read outside mutex lock
1 parent 591cefa commit a8d54d7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

coderd/database/pubsub/pubsub.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ func (p *PGPubsub) subscribeQueue(event string, newQ *msgQueue) (cancel func(),
278278
if len(listeners) == 0 {
279279
delete(p.queues, event)
280280
}
281+
listenerCount := len(listeners)
281282
p.qMu.Unlock()
282283
// as above, we must not hold the lock while calling into pgListener
283284

284-
if len(listeners) == 0 {
285+
if listenerCount == 0 {
285286
uErr := p.pgListener.Unlisten(event)
286287
p.closeMu.Lock()
287288
defer p.closeMu.Unlock()

0 commit comments

Comments
 (0)