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

Fix MQTT reconnection bug #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RosLD
Copy link

@RosLD RosLD commented Jan 31, 2023

Problems found

The first problem I found is that if the iotagent is provisioned with a group, and thus, subscribed to a topic if the broker disconnects in my case does not resubscribe to those topics, hence all the reports made from the devices will be ignored.

The second problem is about a bug in the code. As I could understand, in case of a disconnection it is supposed to wait a larger time every time it tries to reconnect and fail, it will try 5 times, but there is a problem with the function sleep, because it is not executed asynchronously and thus the reconnection times are not incremental, there will be 1 second between each trial because it is the default time in the mqtt library.
I could not fix the async problem either, I think it is related to the mqtt library and how its event handler works.

Proposed changes

  • To fix both problems described I used the option reconnectPeriod when the mqtt client is being created, this way if the mqtt broker dissapears it will try to reconnect every 10 minutes. It will also resubscribe to the topics.
  • I have removed the lines inside the event handler that stops the client from trying to reconnect if it fails 5 times. I find this more logical since if it is the broker which failed you wont need to restart both services, but if there was a reason for stopping it just let me know and I can change it back.
  • I have also removed lines that, as a result of this changes were left unused such as, the sleep function and some variables.

Types of changes

What types of changes does your code introduce to the project: Put
an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to
ask. We're here to help! This is simply a reminder of what we are going
to look for before merging your code.

  • I have read the [CONTRIBUTING][contrib] doc
  • I have signed the [Contributor License Agreement][cla]
  • I have updated the [CHANGE LOG][log]
  • I have added tests that prove my fix is effective or that my
    feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in
    downstream modules

@github-actions
Copy link

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


Daniel seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheckcla in this Pull Request

@RosLD
Copy link
Author

RosLD commented Jan 31, 2023

I have read the CLA Document and I hereby sign the CLA

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

Successfully merging this pull request may close these issues.

None yet

1 participant