Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection issues after network being lost and restored #504

Open
vadym-kozak opened this issue Dec 2, 2022 · 2 comments
Open

Connection issues after network being lost and restored #504

vadym-kozak opened this issue Dec 2, 2022 · 2 comments

Comments

@vadym-kozak
Copy link

vadym-kozak commented Dec 2, 2022

Hi, I have connection issues in case of very bad network connection or even when its being lost and then restored. I did this simulation on iOS using Settings-> Developer -> Network Link Conditioner and switching between different network profiles. Also it is happening in real life when network is unstable.
So code is

mqttClient = CocoaMQTT5(clientID: clientID, host: host, port: 8883)
mqttClient?.username = "username"
mqttClient?.password = "pass"
mqttClient?.autoReconnect = true
mqttClient?.enableSSL = true
mqttClient?.keepAlive = 5
mqttClient?.deliverTimeout = 5
mqttClient?.delegate = self
mqttClient?.logLevel = .debug
------Connected here ------

CocoaMQTT(debug): ping
CocoaMQTT(debug): SEND: PING
CocoaMQTT(debug): ==========================MQTT 5.0==========================
CocoaMQTT(debug): packetFixedHeaderType 192
CocoaMQTT(debug): fixedHeader [192]
CocoaMQTT(debug): remainingLen(len: len) [0]
CocoaMQTT(debug): variableHeader []
CocoaMQTT(debug): properties []
CocoaMQTT(debug): payload []
CocoaMQTT(debug): =============================================================
CocoaMQTT(debug): socket wrote data -192
CocoaMQTT(debug): RECV: PONG
pong

------Disabled network here ------

CocoaMQTT(debug): ping
CocoaMQTT(debug): SEND: PING
CocoaMQTT(debug): ==========================MQTT 5.0==========================
CocoaMQTT(debug): packetFixedHeaderType 192
CocoaMQTT(debug): fixedHeader [192]
CocoaMQTT(debug): remainingLen(len: len) [0]
CocoaMQTT(debug): variableHeader []
CocoaMQTT(debug): properties []
CocoaMQTT(debug): payload []
CocoaMQTT(debug): =============================================================
CocoaMQTT(debug): socket wrote data -192
CocoaMQTT(debug): ping
CocoaMQTT(debug): SEND: PING
CocoaMQTT(debug): ==========================MQTT 5.0==========================
CocoaMQTT(debug): packetFixedHeaderType 192
CocoaMQTT(debug): fixedHeader [192]
CocoaMQTT(debug): remainingLen(len: len) [0]
CocoaMQTT(debug): variableHeader []
CocoaMQTT(debug): properties []
CocoaMQTT(debug): payload []
CocoaMQTT(debug): =============================================================
CocoaMQTT(debug): socket wrote data -192
CocoaMQTT(debug): ping
CocoaMQTT(debug): SEND: PING
CocoaMQTT(debug): ==========================MQTT 5.0==========================
CocoaMQTT(debug): packetFixedHeaderType 192
CocoaMQTT(debug): fixedHeader [192]
CocoaMQTT(debug): remainingLen(len: len) [0]
CocoaMQTT(debug): variableHeader []
CocoaMQTT(debug): properties []
CocoaMQTT(debug): payload []
CocoaMQTT(debug): =============================================================
CocoaMQTT(debug): socket wrote data -192
CocoaMQTT(debug): ping
CocoaMQTT(debug): SEND: PING
CocoaMQTT(debug): ==========================MQTT 5.0==========================
CocoaMQTT(debug): packetFixedHeaderType 192
CocoaMQTT(debug): fixedHeader [192]
CocoaMQTT(debug): remainingLen(len: len) [0]
CocoaMQTT(debug): variableHeader []
CocoaMQTT(debug): properties []
CocoaMQTT(debug): payload []
CocoaMQTT(debug): =============================================================
CocoaMQTT(debug): socket wrote data -192

------Enabled network here ------

2022-12-02 10:09:00.777534+0000 App[67721:4873012] [connection] nw_socket_handle_socket_event [C5:1] Socket SO_ERROR [54: Connection reset by peer]
CocoaMQTT(debug): socket disconnected
disconnect

It's never reconnect again

@leeway1208
Copy link
Collaborator

Hello, mqttClient?.autoReconnect = true is only triggered until ConnAck status is not success.

@mnich0ls
Copy link

I am also having issues during poor network conditions or when switching from Wi-Fi to Cellular due to poor Wi-Fi signal strength or leaving home/access-point.

The issue I've been seeing is that the connection can get hung in the "connecting" state and the timeout never seems to fire. I've added a work-around by setting my own timer when starting a connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants