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

Lines changed: 4 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy