From a5329edae03a057c3fe2dd241f55f4996ab8ab4e Mon Sep 17 00:00:00 2001 From: Matt Brittan Date: Wed, 24 Feb 2021 21:14:46 +1300 Subject: [PATCH] Issue #488 - If options.AutoReconnect is true calling Disconnect could trigger another connection attempt. Signed-off-by: Matt Brittan --- client.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index fade7f4..a3ebc31 100644 --- a/client.go +++ b/client.go @@ -484,10 +484,13 @@ func (c *client) internalConnLost(err error) { DEBUG.Println(CLI, "internalConnLost waiting on workers") <-stopDone DEBUG.Println(CLI, "internalConnLost workers stopped") - if c.options.CleanSession && !c.options.AutoReconnect { + // It is possible that Disconnect was called which led to this error so reconnection depends upon status + reconnect := c.options.AutoReconnect && c.connectionStatus() > connecting + + if c.options.CleanSession && !reconnect { c.messageIds.cleanUp() } - if c.options.AutoReconnect { + if reconnect { c.setConnected(reconnecting) go c.reconnect() } else {