CocoaMQTT icon indicating copy to clipboard operation
CocoaMQTT copied to clipboard

didConnectAck not always called on connect

Open martyhoogendam opened this issue 6 years ago • 6 comments

Connecting to the broker works 95% of the time. Once in a while, I see in the logs:

CocoaMQTT(debug): socketDidSecure CocoaMQTT(debug): Socket write message with tag: 0 CocoaMQTT(debug): reader header ready: 32 CocoaMQTT(debug): CONNACK Received: 0

But didConnectAck is never called. And there is no error: the keep alive heartbeat works. Other times the CONNACK is NOT received and didConnectAck is also not called. It gets stuck in an in-between state. It will not auto-reconnect and there is no error.

This is a huge problem because the subscriptions never get initiated and there is no error I can handle.

martyhoogendam avatar Feb 20 '19 10:02 martyhoogendam

Hi, @martyhoogendam What is the MQTT Broker? And can you paste the connect code?

HJianBo avatar Feb 20 '19 11:02 HJianBo

Hi @HJianBo The broker is EMQX 3.0.1 The connect code is:

self.cocoaMQTT = CocoaMQTT(clientID: clientId, host: Environment.shared.mqttHost, port: Environment.shared.mqttPort)
self.cocoaMQTT.cleanSession = false
self.cocoaMQTT.keepAlive = 60
self.cocoaMQTT.enableSSL = true
self.cocoaMQTT.autoReconnect = true
self.cocoaMQTT.autoReconnectTimeInterval = 1 // In seconds
self.cocoaMQTT.logLevel = Environment.shared.deployment == .production ? .off : .debug
self.cocoaMQTT.dispatchQueue = DispatchQueue.global(qos: .userInitiated)

And then of course there is the setup of username/password and the closures. I've already tried using this pull request https://github.com/emqtt/CocoaMQTT/pull/246 which does fix autoreconnect and keepalive on the background queue, but does not fix the missing didConnectAck calls.

martyhoogendam avatar Feb 20 '19 18:02 martyhoogendam

Hi, @martyhoogendam Sorry too late reply.

I have released the v1.2.0 version. It has merged the #246 RP. Can test this issue on the last version?

HJianBo avatar May 03 '19 01:05 HJianBo

Hi, @martyhoogendam Is the problem solved now?

HJianBo avatar May 20 '19 08:05 HJianBo

This issue still persists

abhriyaroy avatar Apr 29 '20 06:04 abhriyaroy

@HJianBo faced same issue with CocoMQTT 2.1.6, I cloud send msg to mqttx client , but I always didn't receive any message,the didConnectAck method not response.

wtdu avatar Sep 19 '23 02:09 wtdu