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: Wait for MQTT subscriptions to take effect before returning (#516) #517

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

Conversation

eaton-coreymutter
Copy link
Contributor

MQTTAsync_subscribe() is async. There are some places e.g. startConfigured() where we expect the subscription to be in effect right after this call. So wait for completion before returning.

Fixes: #516

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/device-sdk-c/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?) (no unit tests at all yet)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?) N/A

Testing Instructions

Before and after change, on a busy system, repeatedly have a C-based device service start and upload its devices (deleting them from core-metadata each time), to reproduce the bug in the related issue.

New Dependency Instructions (If applicable)

…exfoundry#516)

MQTTAsync_subscribe() is async. There are some places e.g. startConfigured()
where we expect the subscription to be in effect right after this call.
So wait for completion before returning.

Fixes: edgexfoundry#516

Signed-off-by: Corey Mutter <[email protected]>
@eaton-coreymutter eaton-coreymutter changed the title bug: Wait for MQTT subscriptions to take effect before returning (#516) fix: Wait for MQTT subscriptions to take effect before returning (#516) Oct 23, 2024
@@ -73,6 +73,10 @@ static void edgex_bus_mqtt_subscribe (void *ctx, const char *topic)
{
iot_log_error (cinfo->lc, "mqtt: unable to subscribe to %s, error code %d", topic, rc);
}
else
{
MQTTAsync_waitForCompletion(cinfo->client, opts.token, 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could consider adding a check for the return code of MQTTAsync_waitForCompletion. If the return code is not MQTTASYNC_SUCCESS, logging it could be helpful for diagnosing problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eaton-coreymutter Just wanted to confirm the idea of adding a return code check for MQTTAsync_waitForCompletion. What are your thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a good idea, I will add the change soonish, or you are welcome to.

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.

Uploaded devices sometimes not in devmap (race condition)
2 participants