From 8e2c2327d5405bc0e2f01ee35886ce0f216c6a5f Mon Sep 17 00:00:00 2001 From: Marcelo Pires Date: Thu, 6 Sep 2018 15:37:42 +0200 Subject: [PATCH] remove all subscription in Disconnect remove subscription in unsubscribe --- transport/websocket/websocket.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/transport/websocket/websocket.go b/transport/websocket/websocket.go index c85362b..a7334f8 100644 --- a/transport/websocket/websocket.go +++ b/transport/websocket/websocket.go @@ -202,6 +202,12 @@ func (w *Websocket) Disconnect() error { w.stopCh <- nil close(w.stopCh) + w.subsMu.Lock() + for i := range w.subs { + close(w.subs[i]) + delete(w.subs, i) + } + w.subsMu.Unlock() return w.sendMessage(&m) } @@ -245,6 +251,14 @@ func (w *Websocket) Unsubscribe(subscription string) error { ClientId: w.clientID, Id: w.nextMsgID(), } + w.subsMu.Lock() + sub, ok := w.subs[subscription] + if ok { + close(sub) + delete(w.subs, subscription) + } + w.subsMu.Unlock() + return w.sendMessage(m) }