Skip to content

MMQTTException vs partial reads on read timeout #201

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
vladak opened this issue Jan 29, 2024 · 0 comments
Closed

MMQTTException vs partial reads on read timeout #201

vladak opened this issue Jan 29, 2024 · 0 comments

Comments

@vladak
Copy link
Contributor

vladak commented Jan 29, 2024

The common use case of the library is as follows (adapted from #163 (comment)):

while True:
    temperature = dps310.temperature
    mqtt_client.publish("foo", temperature)

    try:
        mqtt_client.loop()
    except (MMQTTException) as e:
        print("MQTTException: \n", e)
        time.sleep(300)
        continue

The documentation of the MMQTTException does not give any advice as to what to do if the exception is raised. Usually, the safest thing would be to reconnect() on the exception, notably because as indicated on #175 (comment) the message data could be partially read and lost when the exception is raised which would result in garbage on the next read.

There are two choices:

  • easy: augment the MMQTTException docstring to say a reconnect() is needed upon catching it
  • more difficult: to allow for the graceful handling of the read timeout, the buffer should be kept around so that message reassembly can be performed
vladak added a commit to vladak/Adafruit_CircuitPython_MiniMQTT that referenced this issue Jan 28, 2025
use it for protocol/network/system level errors only

fixes adafruit#201
@tyeth tyeth closed this as completed in fdd436e Mar 12, 2025
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

1 participant