CocoaMQTT icon indicating copy to clipboard operation
CocoaMQTT copied to clipboard

Manual disconnection did not work as expected

Open ckfear opened this issue 2 years ago • 4 comments

I call mqtt.disconnect,but it still reconnect.I found the variable is_internal_disconnected is always true.

public func disconnect() {
    is_internal_disconnected = false
    internal_disconnect()
}
    
/// Disconnect unexpectedly
func internal_disconnect() {
    is_internal_disconnected = true
    send(FrameDisconnect(), tag: -0xE0)
    socket.disconnect()
}

And the automatic reconnection logic doesn't look right.

if !autoReconnect{
    guard !is_internal_disconnected else {
        return
    }
}

guard autoReconnect else {
    return
}

The above code makes the is_internal_disconnected variable meaningless.As I understand it, if I disconnect from the outside, it should not automatically reconnect.

ckfear avatar Jul 05 '22 01:07 ckfear

I submitted the pr #466 to fix the problem.

ckfear avatar Jul 05 '22 01:07 ckfear

Thank you for your support.😄

leeway1208 avatar Jul 08 '22 07:07 leeway1208

Trying to use mqtt!.autoReconnect = false. Is it work?

leeway1208 avatar Jul 08 '22 08:07 leeway1208

It's ok.But I think external disconnection and internal disconnection should be different behaviours. And the parameter is_internal_disconnected should work.

ckfear avatar Jul 14 '22 07:07 ckfear

@ckfear Yes. you are right. I misunderstood. Thank you for your contribution!

leeway1208 avatar Aug 26 '22 13:08 leeway1208