emqx / emqx-sn

EMQX MQTT-SN Gateway
https://www.emqx.com
Apache License 2.0
30 stars 20 forks source link

UNSUBSCRIBE without a payload disconnects the client #50

Closed jpmzometa closed 6 years ago

jpmzometa commented 7 years ago

Due to an error, a connected client sent an UNSUBSCRIBE without a payload to the MQTT-SN gateway. I notice that the client is disconnected immediately after without any notification.

grutabow commented 7 years ago

"an UNSUBSCRIBE without a payload" means an UNSUBSCRIBE without TopicId? This UNSUBSCRIBE is not a complete MQTT-SN packet, right? If it is true, emq-sn would be confused of the incoming packet and false-interpret this packet and next packet. If fortunate enough, it can recover from such an error.

jpmzometa commented 7 years ago

Yes, it is an invalid/incomplete packet. The problem is that the gateway immediately loses/closes the connection with the client (but without an DISCONNECT acknowledgement).

grutabow commented 6 years ago

MQTT-SN spec does not state how to handle an invalid packet. But MQTT spec has addressed that

Unless stated otherwise, if either the Server or Client encounters a protocol violation, it MUST close the Network Connection on which it received that Control Packet which caused the protocol violation.

So it is reasonable to close connection without a notification in this case.

What do you think about it?

jpmzometa commented 6 years ago

I think it's fine. I wasn't sure if that was the intended behaviour or some kind of internal problem in the plugin. Thanks for the clarification.