Skip to content

Conversation

@smaeul
Copy link
Contributor

@smaeul smaeul commented Nov 17, 2025

MQTT v3.1.1 requires: "If a server sends a CONNACK packet containing a non-zero return code it MUST then close the Network Connection [MQTT-3.2.2-5]."

MQTT v5.0 requires: "If a Server sends a CONNACK packet containing a Reason code of 128 or greater it MUST then close the Network Connection [MQTT-3.2.2-7]."

Since the network connection is guaranteed to be closed from the server side, the library can detect this and request to close the socket on the client side.

The user could handle this by separately parsing the NotifyPacketReceived(Connack) event, but this seems like a reasonable convenience to provide for clients that don't care about the reason code, if you agree. This ordering was simplest to implement, but may be the RequestClose event should come after the NotifyPacketReceived?

MQTT v3.1.1 requires: "If a server sends a CONNACK packet containing a
non-zero return code it MUST then close the Network Connection
[MQTT-3.2.2-5]."

MQTT v5.0 requires: "If a Server sends a CONNACK packet containing a
Reason code of 128 or greater it MUST then close the Network Connection
[MQTT-3.2.2-7]."

Since the network connection is guaranteed to be closed from the server
side, the library should detect this and request to close the socket on
the client side.
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.88%. Comparing base (609c3a3) to head (fc98b6f).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/mqtt/connection/core.rs 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
- Coverage   90.90%   90.88%   -0.03%     
==========================================
  Files          55       55              
  Lines        7456     7458       +2     
==========================================
  Hits         6778     6778              
- Misses        678      680       +2     
Files with missing lines Coverage Δ
src/mqtt/connection/core.rs 86.26% <0.00%> (-0.11%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redboltz
Copy link
Owner

According to the MQTT specification, when a CONNACK packet with an error and/or a DISCONNECT packet is sent, the sender must close the connection. This allows the underlying layers to shut down gracefully.
If the receiver also initiates a close, it may interfere with this graceful shutdown process. Therefore, mqtt-protocol-core does not close the connection from the receiver side.

If the underlying layer does not detect that the connection has been closed within a certain period after receiving a CONNACK-with-error or DISCONNECT packet, the user may choose to close the connection manually.

@smaeul
Copy link
Contributor Author

smaeul commented Nov 18, 2025

OK, I can handle this in my event loop.

@smaeul smaeul closed this Nov 18, 2025
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