Reconnecting smoothly
See original GitHub issueHello,
First thanks for creating/maintaining this sdk. From the documentation, it states that you provide:
It provides basic synchronous MQTT operations in the classic MQTT publish-subscribe model, along with configurations of on-top features: - Auto reconnect/resubscribe - Progressive reconnect backoff - Offline publish requests queueing with draining
However, I’m not experiencing these features. I expect when I call awsMQTTClient.publish(topic, message, qos) I expect not to ever get a publishTimeoutException(), except maybe when the maxReconnectQuietTimeSecond in configureAutoReconnectBackoffTime (docs) is exceeded. However, I get publishTimeoutException() quite often.
Do I have to do something like this now everytime I publish?
try:
myMQTTClient.publish("testing/IoT", message, 1)
except:
print(err)
myMQTTClient.connect()
myMQTTClient.publish("testing/IoT", message, 1)
What’s the proper way of recovering from this type of timeout?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)

Top Related StackOverflow Question
Publishes do not affect the client’s attempts to reconnect. Reconnects occur when the underlying socket reports that the connection is lost, or when the MQTT Client doesn’t get a response to the PING packets it is sending to the server at regular intervals (“keep alive” values affect the rate that these PING packets are sent)
Just noting that I had a similar issue when running inside uwsgi (using Flask), in case anyone else comes across this and needs help.
I fixed it by making sure to construct and connect my AWSIoTMQTTClient instance in the same context (probably a thread?) that requests run in. I still reuse the instance between different requests though, because calling connect() on the client takes some time.