Repository navigation
fix(sensors): keep a retained MQTT message before acknowledging it - #299
Merged
Merged
Conversation
The hub sent PUBACK/PUBREC before it stored and forwarded the message, so a client that subscribed right after the publisher's acknowledgement could miss the retained copy and get it as a live message instead. This made test_broker_is_an_ordinary_local_broker fail now and then in CI (seen on #253). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GbW6SC3MU2AmYQ9zFa5dk4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Adeel · project thread
Description
Before: Lens's MQTT hub acknowledged a QoS 1/2 publish (PUBACK/PUBREC) before it stored the retained copy and passed the message on. A device that subscribed right after the publisher got its acknowledgement could miss the retained message and get it as a live one (retain flag off) instead.
After: the hub keeps and forwards the message first, then acknowledges it, then tells Lens about it. A subscriber that comes after the acknowledgement always gets the retained copy.
Motivation and Context
tests/api/test_sensors.py::test_broker_is_an_ordinary_local_brokerfailed now and then in CI because of this race (seen on #253's "FastAPI (SurrealDB server)" job:assert ('home/kitchen/temp', b'21.5', False) == (..., True)). Fixing the race fixes the red check rather than re-running it.Steps to reproduce (if appropriate):
The new test
test_a_retained_message_is_kept_before_its_sender_hears_it_arrivedslows the hub's publish by 0.3 s: it fails on main and passes with this change.Types of changes
!in the title)Checklist:
Done questions (AGENTS.md)
🤖 Generated with Claude Code
https://claude.ai/code/session_01GbW6SC3MU2AmYQ9zFa5dk4
Generated by Claude Code