Skip to content
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

client.loop if the MQTT Broker goes down the loop crashes with OSError: [Errno 104] ECONNRESET #194

Open
SRMAX opened this issue Dec 21, 2023 · 3 comments

Comments

@SRMAX
Copy link

SRMAX commented Dec 21, 2023

In the mqtt_client.loop if the MQTT Broker goes down the loop crashes with OSError: [Errno 104] ECONNRESET. This leaves no way to handle the error in the program. It should return with regular error handling so the program can either wait for the broker to come back online or exit gracefully.

Running:
Adafruit CircuitPython 8.2.9 on 2023-12-06; Adafruit QT Py ESP32-S3 no psram with ESP32S3
Library : adafruit-circuitpython-bundle-8.x-mpy-20231215

Error:
Published to test/qtpy32/status/publish with PID 1
OK Message sent to MQTT Server!

Traceback (most recent call last):
File "code.py", line 201, in
File "adafruit_minimqtt/adafruit_minimqtt.py", line 788, in publish
OSError: [Errno 104] ECONNRESET

See attached txt file for code.py
code.txt

@vladak
Copy link
Contributor

vladak commented Jan 31, 2024

I assume that line 788 that leads to the exception is one of the self._sock.send() calls inside publish(). The error can be handled like this:

try:
    mqtt_client.publish(...)
except OSError as e:
    mqtt_client.reconnect()
    mqtt_client.publish(...)

What do you propose ? Wrap the OSError inside MMQTTException or something else ?

@SRMAX
Copy link
Author

SRMAX commented Jan 31, 2024

I did have a MQTTException that wasn't handled that I believe should have been. If it had returned and exception I could have handled it. Because it wasn't the result is very unstable code. If I'm overlooking something please tell me.

@vladak
Copy link
Contributor

vladak commented Jan 31, 2024

I don't follow. The original comment says OSError which is exception however distinct from MMQTTException.

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

2 participants