eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
314 stars 179 forks source link

Timeout not handled correctly #214

Closed Jochen0x90h closed 3 years ago

Jochen0x90h commented 3 years ago

Hi!

I encoutered the following problem: When my mqtt-sn cient exceeds the timeout, it gets disconnected by mosquitto. Then, if my client sends a PINGREQ wich is late, mosquitto sees a new connection and disconnects it due to protocol error:

1600375626: Client myClient has exceeded timeout, disconnecting.
1600375670: New connection from 127.0.0.1 on port 1883.
1600375670: Client <unknown> disconnected due to protocol error.

The gateway only reports

20200917 224750.463   PINGREQ           <---  myClient                            02 16
20200917 224750.464   PINGREQ           ===>  myClient                            C0 00

Correct behavior would be to reply to the client with a DISCONNECT message according to the sepecification

ty4tw commented 3 years ago

Hi,

Correct behavior would be to reply to the client with a DISCONNECT message according to the specification.

Could you tell me where in the specifications it is written?

Jochen0x90h commented 3 years ago

Hi,

In MQTT For Sensor Networks (MQTT-SN), Protocol Specification, Version 1.2

In 5.4.21: "A server or gateway may also sends a DISCONNECT to a client, e.g. in case a gateway, due to an error, cannot map a received message to a client. Upon receiving such a DISCONNECT message, a client should try to setup the connection again by sending a CONNECT message to the gateway or server."

ty4tw commented 3 years ago

"A gateway cannot map a received message to a client." is ambiguous.

In case of keep alive timeout, A broker closes a session without DISCONNECT message. The gateway receives No message. If it is means that a gateway cannot send a received message from a client to a broker/server, a gateway should send a DISCONNECT to the client.