We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Client.loop_stop expects that self._thread stays valid, but _thread_main unsets self._thread after exiting, causing a race-condition:
Client.loop_stop
self._thread
_thread_main
$ python3 test.py Traceback (most recent call last): File "test.py", line 14, in <module> client.loop_stop() File "src/paho/mqtt/client.py", line 2365, in loop_stop self._thread.join() ^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'join'
Trigger it by applying this patch to paho-mqtt, which simply adds a wait, so _thread_main always wins the race:
diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index 4ccc869..dc01f5e 100644 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -2360,6 +2360,7 @@ class Client: return MQTTErrorCode.MQTT_ERR_INVAL self._thread_terminate = True + time.sleep (2) if threading.current_thread() != self._thread: self._thread.join()
Then run this minimal MQTT client:
import time from paho.mqtt.client import Client from paho.mqtt.enums import CallbackAPIVersion, MQTTProtocolVersion client = Client(CallbackAPIVersion.VERSION2, 'testclient', protocol=MQTTProtocolVersion.MQTTv5) client.loop_start() client.connect(host='localhost') time.sleep (2) client.disconnect() client.loop_stop()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug Description
Client.loop_stop
expects thatself._thread
stays valid, but_thread_main
unsetsself._thread
after exiting, causing a race-condition:Reproduction
Trigger it by applying this patch to paho-mqtt, which simply adds a wait, so
_thread_main
always wins the race:Then run this minimal MQTT client:
Environment
The text was updated successfully, but these errors were encountered: