Skip to content

Commit

Permalink
properly close pub channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Yang committed Jun 3, 2024
1 parent 15708d5 commit 87e988b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ func (mw *pubMWriter) addConn(w *Conn) {
mw.subscribers[w] = c
go func() {
for {
msg := <-c
msg, ok := <-c
if !ok {
break
}
topic := string(msg.Frames[0])
if w.subscribed(topic) {
_ = w.SendMsg(msg)
Expand All @@ -268,9 +271,10 @@ func (mw *pubMWriter) rmConn(w *Conn) {
mw.mu.Lock()
defer mw.mu.Unlock()

if _, ok := mw.subscribers[w]; ok {
if channel, ok := mw.subscribers[w]; ok {
_ = w.Close()
delete(mw.subscribers, w)
close(channel)
}
}

Expand Down

0 comments on commit 87e988b

Please sign in to comment.