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

MMQTTException vs partial reads on read timeout #201

Open
vladak opened this issue Jan 29, 2024 · 0 comments
Open

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
  • 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
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