paho.mqtt.python icon indicating copy to clipboard operation
paho.mqtt.python copied to clipboard

wait_for_publish() deadlocks with qos=2 on server or connection shutdown

Open philipp-schmidt opened this issue 4 years ago • 2 comments

I am using loop_start() and publish messages with qos level 2 and then wait for the message to be properly published via wait_for_publish(). Stopping the mqtt server sometimes results in a race condition where wait_for_publish() will lock up infinitely, probably waiting for the qos handshake to finish, but the connection is already dead. This completely deadlocks the thread. The automatic reconnect of loop_start() does not resolve this either, even if the server restarts.

topic = "test"
payload = "test"
publish_status = client.publish(topic, payload, qos=2)
# This will sometimes deadlock when shutting down the server externally or dropping connection
publish_status.wait_for_publish()

philipp-schmidt avatar Oct 24 '21 15:10 philipp-schmidt

I inspect the same behaviour with qos=1 and a Mosquitto broker.

The Mosquitto server timeouts the client, but the python program is still running.

swamper123 avatar Dec 15 '21 09:12 swamper123

Apologies for the delay in someone looking into this.

I'd appreciate it if someone could confirm if this is still an issue with the current release and provide a reproducer and/or logs (understand that this might be difficult to reproduce). In theory the client should reconnect, and the publish process should conclude as normal (but this gets complicated and I have not traced in detail).

MattBrittan avatar Jan 07 '24 03:01 MattBrittan