8000 umqtt.simple's check_msg triggers OSError -1 with TLS servers · Issue #5451 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

umqtt.simple's check_msg triggers OSError -1 with TLS servers #5451

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

Closed
SylvainGarrigues opened this issue Dec 23, 2019 · 7 comments
Closed

Comments

@SylvainGarrigues
Copy link

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.

@MrSurly
Copy link
Contributor
MrSurly commented Dec 23, 2019

Which board?

@SylvainGarrigues
Copy link
Author

I reproduced this issue on my Mac (MicroPython 1.11) and on my LoLin NodeMCU v3 board from wemos.cc (MicroPython 1.12).

@peterhinch
Copy link
Contributor

TLS on nonblocking sockets is a known issue, mentioned in my comment here. My experience is that TLS on nonblocking sockets works on Pyboard D but not on ESPx.

@SylvainGarrigues
Copy link
Author
SylvainGarrigues commented Dec 24, 2019

I thought
c764453 implemented non-blocking TLS sockets for ESP8266-based boards, doesn’t it?

@MrSurly
Copy link
Contributor
MrSurly commented Dec 24, 2019

TLS on nonblocking sockets is a known issue, mentioned in my comment here. My experience is that TLS on nonblocking sockets works on Pyboard D but not on ESPx

It's implemented on ESP32.

@odewdney
Copy link
Contributor

i was just about to create a pull request to update axtls, for this, when i found that its already been fixed in
pfalcon/axtls@f38bdcb
(and other places!) - basically it was sending a tls alert on EAGAIN, killing the connection.

@jonnor
Copy link
Contributor
jonnor commented Sep 2, 2024

Already fixed, according to above comments.

@jonnor jonnor closed this as completed Sep 2, 2024
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

5 participants
0