fix: enforce per-channel MQTT connection state guard - #6983
Conversation
…nnect operations and duplicate connect Co-Authored-By: Claude <noreply@anthropic.com>
Aias00
left a comment
There was a problem hiding this comment.
The duplicate-CONNECT path looks like it needs cleanup before closing the channel. A successful first CONNECT registers the channel in , but this new early return only calls . I only see repository cleanup in the explicit DISCONNECT flow, and there does not appear to be centralized \ cleanup for MQTT channels, so a client that sends CONNECT twice can leave a closed channel referenced in . Could you remove the channel from \ before closing here, or add centralized channel-inactive cleanup for all server/client close paths?
|
Correction to my previous review comment, where inline code formatting was stripped by my local shell: The duplicate-CONNECT path looks like it needs cleanup before closing the channel. A successful first CONNECT registers the channel in |
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary
Changes:
MessageType.java— connection state moved from a per-instancevolatile boolean(dead:MqttFactorybuilds a freshMessageTypeper inbound message, so the state set byConnect.connect()never propagated to other handlers) to a per-channelAttributeKey<Boolean>;isConnected(Channel)/setConnected(Channel, boolean)now read/write the channel attribute.Publish.java,Unsubscribe.java,PingReq.java— guards inverted toif (!isConnected(ctx.channel())); likeSubscribe, the channel is now closed (FIRE_EXCEPTION_ON_FAILURE) instead of silently dropping the packet.Subscribe.java— inverted the deadif (isConnected())guard.Connect.java— duplicate CONNECT on the same channel is rejected by closing the connection without sending a CONNACK ([MQTT-3.1.0-2]).Test Cases:
ConnectTest— migrated from Mockito mocks to a realEmbeddedChannel(per-channel attributes require a real channel); addedduplicateConnectIsRejected(second CONNECT receives no CONNACK and closes the channel).PublishTest— addedpublishBeforeConnectClosesChanneland the end-to-endpublishAfterConnectOnSameChannelIsAccepted(realConnect.connect()followed byPublish.publish()on the same channel).PingReqTest—pingReqBeforeConnectClosesChannel,pingReqAfterConnectSendsPingResp.UnsubscribeTest—unsubscribeBeforeConnectClosesChannel.Verification
shenyu-protocol-mqttmodule: 13 tests passed (ConnectTest 5, PublishTest 5, PingReqTest 2, UnsubscribeTest 1), JDK 21.close #6638