Skip to content

Commit 0db909c

Browse files
committed
fix: close pg PubSub listener to avoid race
1 parent 5bfbf9f commit 0db909c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

coderd/database/pubsub/pubsub.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,11 @@ func (p *pgPubsub) Publish(event string, message []byte) error {
239239

240240
// Close closes the pubsub instance.
241241
func (p *pgPubsub) Close() error {
242-
p.cancel()
242+
// canceling the context also causes the listener to be closed, so directly
243+
// close it before canceling the context to avoid the race. If we lost the
244+
// race we'd return an error about the listener already being closed.
243245
err := p.pgListener.Close()
246+
p.cancel()
244247
<-p.listenDone
245248
return err
246249
}

0 commit comments

Comments
 (0)