diff --git a/broker/client.go b/broker/client.go index 7cc703d..955254e 100644 --- a/broker/client.go +++ b/broker/client.go @@ -180,6 +180,12 @@ func (c *client) readLoop() { return } + // if packet is disconnect from client, then need to break the read packet loop and clear will msg. + if _, isDisconnect := packet.(*packets.DisconnectPacket); isDisconnect { + c.info.willMsg = nil + c.cancelFunc() + } + msg := &Message{ client: c, packet: packet,