Skip to content

Fix MQTT protocol compliance: QoS 2 flow, SUBACK, add DISCONNECT handler#20

Merged
kerryjiang merged 2 commits intomasterfrom
copilot/check-mqtt-implementation
Jan 31, 2026
Merged

Fix MQTT protocol compliance: QoS 2 flow, SUBACK, add DISCONNECT handler#20
kerryjiang merged 2 commits intomasterfrom
copilot/check-mqtt-implementation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

Addresses MQTT 3.1.1 protocol compliance gaps and missing command handler.

Bug Fixes

  • QoS 2 flow: PUBREC now responds with PUBREL (0x62), PUBREL responds with PUBCOMP (0x70). Previously both echoed their own packet type back.
  • SUBACK response: Returns granted QoS per topic filter instead of only the first topic's QoS.

New Features

  • DISCONNECT handler: Closes session gracefully on client disconnect. Topic cleanup handled by existing TopicMiddleware.UnRegisterSession.

Tests

Added 22 tests (48 total) covering:

  • All command handlers including edge cases (empty topic, no subscribers, multiple subscribers)
  • Packet encoding/decoding via MQTTPacketDecoder
  • Complete QoS 2 flow sequence
  • TopicMiddleware session cleanup
// QoS 2 flow now correct:
// Client PUBREC → Server PUBREL (0x62)
// Client PUBREL → Server PUBCOMP (0x70)

// SUBACK now returns QoS per topic:
// Subscribe to 2 topics with QoS 0 and 1
// Response: [0x90, 0x04, packetId_hi, packetId_lo, 0x00, 0x01]

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… comprehensive tests

Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Copilot AI changed the title [WIP] Check and complete missing parts in MQTT implementation Fix MQTT protocol compliance: QoS 2 flow, SUBACK, add DISCONNECT handler Jan 31, 2026
Copilot AI requested a review from kerryjiang January 31, 2026 06:06
@kerryjiang kerryjiang marked this pull request as ready for review January 31, 2026 06:18
@kerryjiang kerryjiang merged commit 073fd7f into master Jan 31, 2026
3 checks passed
@kerryjiang kerryjiang deleted the copilot/check-mqtt-implementation branch January 31, 2026 06:18
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.

2 participants