Repository navigation
fix(mqtt): close the connection on a second CONNECT - #14809
Conversation
MQTT 3.1.1 and 5.0 both treat a second CONNECT on one network connection as a protocol error. The server handed it to the handler again, which could rebind the client id and identity of a live session. It now disconnects with reason 0x82 (5.0) or closes the socket (3.1.1), and no longer re-arms keep-alive for a connection that closed while its packet was handled.
|
Review complete. No blocking issues — approved ✅; 2 nitpicks below. 🧹 Nitpicks (2) — 🟢 2 low
This PR makes the MQTT broker reject a second CONNECT received on an already-established connection: V5 clients get a DISCONNECT packet with reason code 0x82 (protocol error) before close, while 3.1.1 clients are simply disconnected. The change spans the packet model, connection dispatch, and server-side handling, and adds a recording test fixture plus version-specific regression tests.
Reviewed commit: 8c9c1a4 |
🟢 Tier S · Ready to mergeThe MQTT server tracks whether a network connection has completed CONNECT and rejects duplicate CONNECT packets with the appropriate MQTT 5.0 protocol-error DISCONNECT or MQTT 3.1.1 socket close. It also avoids rearming keep-alive after packet handling closes a connection. Regression coverage verifies handler identity and indexing behavior, including the broker revoke flow. Latest changes: The newest commit updates the revoke regression test to assert that a duplicate CONNECT closes the connection with a Protocol Error and leaves neither identity indexed, rather than expecting the second identity to replace the first.
📂 Walkthrough · 6
Reviewed the commits since |
|
Addressed both nitpicks in the latest commit: the failure message now states the expectation (the client id stays the first CONNECT's), and the 3.1.1 test is renamed to |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
The realtime revoke test relied on a second CONNECT rebinding the connection to another user and project. The broker now refuses it as a protocol error, so the test asserts the DISCONNECT and that neither identity stays indexed.
fix(mqtt): close the connection on a second CONNECT (cherry picked from commit 5d68088)
Summary
MQTT 3.1.1 and 5.0 require the server to treat a second CONNECT on the same network connection as a protocol error and close it.
Utopia\Mqtt\Serverpassed it to the handler again, which could rebind the client id and identity of an established session.Connection::$connectedrecords the first CONNECT; a second one disconnects with reasonDisconnect::PROTOCOL_ERROR(0x82) on 5.0 and closes the socket on 3.1.1, without reaching the handler.receive()no longer re-arms the keep-alive timer for a connection that closed while its packet was handled.Test plan
bin/monorepo check mqttbin/monorepo test mqtt(unit and e2e tiers); the two newConnectionTestcases fail without the fixtests/unit/Mqtt:RevokeTestused to expect a second CONNECT on one connection to re-index it under a new user and project. It now asserts the protocol-error DISCONNECT and that neither identity stays indexed.Related: appwrite-labs/cloud#6666