micropython / micropython/micropython-lib
umqtt.simple's check_msg triggers OSError -1 with TLS servers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Description
Please consider this code:
import utime
from umqtt.simple import MQTTClient
mqtt = MQTTClient("test_mqtt_client_id", "test.mosquitto.org",
port=8883, keepalive=30, ssl=True)
def on_topic_updated(topic, msg):
print((topic, msg))
mqtt.set_callback(on_topic_updated)
mqtt.connect()
mqtt.subscribe(b"Topic/For/Sylvain")
while True:
print("Checking msg...")
mqtt.check_msg()
utime.sleep(1)
It systematically gives the same output (and I can reproduce it with another broker e.g. AWS IoT)
$ /usr/local/Cellar/micropython/1.11/bin/micropython main.py
Checking msg...
Checking msg...
Traceback (most recent call last):
File "main.py", line 15, in <module>
File "/Users/sylvain/.micropython/lib/umqtt/simple.py", line 204, in check_msg
File "/Users/sylvain/.micropython/lib/umqtt/simple.py", line 173, in wait_msg
OSError: -1
What's strange is that if I use port 1883 and ssl=False (i.e. no encryption), the same code works.
I reproduced this issue on my Mac (MicroPython 1.11) and on my ESP8266 board (MicroPython 1.12).
Looping over mqtt.wait_msg() works like a charm, so I suspect switching back and forth a TLS socket from blocking to non-blocking generates such error.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read umqtt/simple.py around check_msg() and wait_msg(), then reproduce the example with a TLS broker and compare it with the working wait_msg() loop. Done means check_msg() can be used repeatedly with TLS without raising OSError -1, while the existing wait_msg() behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100