Skip to content

#55: Wait on MQTT publish queue instead of sleeping - #56

Closed
Aydogan Ersoz (silabs-aydogane) wants to merge 1 commit into
SiliconLabsSoftware:mainfrom
silabs-aydogane:GH-55-mqtt-publish-queue-wait
Closed

#55: Wait on MQTT publish queue instead of sleeping#56
Aydogan Ersoz (silabs-aydogane) wants to merge 1 commit into
SiliconLabsSoftware:mainfrom
silabs-aydogane:GH-55-mqtt-publish-queue-wait

Conversation

@silabs-aydogane

@silabs-aydogane Aydogan Ersoz (silabs-aydogane) commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Issue

Closes: #55

Change

  • Wait on the MQTT publish queue instead of sleeping when it is empty. publish_queue.pop() returns as soon as a message is pushed.
  • Drain the other MQTT queues (subscribe, unsubscribe, unretain, reset) with non-blocking try_pop().

Checklist

Signed-off-by: Aydogan Ersoz <aydogan.ersoz@silabs.com>
@cursor

cursor Bot commented Sep 2, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes timing and scheduling on the MQTT handler thread, which serializes all broker I/O; publish latency should improve but subscribe/unretain handling now interleaves differently with blocking publish waits.

Overview
Refactors mqtt_handler::run() so outbound publishes wake the handler promptly instead of waiting for a fixed poll/sleep cycle.

Non-publish work (reset, subscribe, unsubscribe, unretain) is still drained each iteration with non-blocking try_pop(). The loop then blocks on publish_queue.pop() for up to mqtt_client_poll_interval, which returns as soon as a publish is queued, processes that message, and bursts any additional queued publishes with try_pop(). The old processed_any flag and unconditional sleep when every queue was empty are removed in favor of this timed wait on the publish queue.

Reviewed by Cursor Bugbot for commit 6697047. Configure here.

@silabs-aydogane Aydogan Ersoz (silabs-aydogane) added Bug Issue is a bug report Silicon Labs development PR contents developed by Silicon Labs labels Sep 2, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6697047. Configure here.

Comment thread components/mqtt/src/mqtt_handler.cpp
@silabs-aydogane Aydogan Ersoz (silabs-aydogane) added the CTT Requested (Full Set) CTT Testing with full scope is requested from CTT Automation label Sep 2, 2026
@siliconlabsdevops-svc-devops siliconlabsdevops-svc-devops Bot removed the CTT Requested (Full Set) CTT Testing with full scope is requested from CTT Automation label Sep 2, 2026
@siliconlabsdevops-svc-devops

Copy link
Copy Markdown

CTT Jenkins job: $zpc_ctt_jenkins_url/job/zw-ctt-automation-multibranch/job/main/3612/

@silabs-aydogane
Aydogan Ersoz (silabs-aydogane) marked this pull request as draft September 3, 2026 08:05
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Bug Issue is a bug report Silicon Labs development PR contents developed by Silicon Labs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MQTT publish can wait up to 100 ms before being sent

2 participants