remove subscriptions when a client disconnect

This commit is contained in:
Marc Magnin
2019-01-18 14:38:51 +01:00
parent 7c4d7a0c06
commit cf77eaf346

View File

@@ -112,6 +112,14 @@ func (c *client) readLoop() {
log.Error("read packet error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
msg := &Message{client: c, packet: DisconnectdPacket}
b.SubmitWork(msg)
// remove subscriptions related to that client
for topic, sub := range c.subMap {
t := []byte(topic)
c.topicsMgr.Unsubscribe(t, sub)
c.session.RemoveTopic(topic)
delete(c.subMap, topic)
}
return
}