emqx / emqx

The most scalable open-source MQTT broker for IoT, IIoT, and connected vehicles
https://www.emqx.com/
Other
13.93k stars 2.22k forks source link

CoAP heartbeat returns 2.04 on terminated client (not registered client) #10092

Open TomazCebekAstron opened 1 year ago

TomazCebekAstron commented 1 year ago

What happened?

I did a test of the coap gateway. I connected a client (connected mode) by the connect packet on my emqx broker and everything was working from subscribe to publish and heartbeat. I had a client active for 10 minutes (heartbeat settings set to 300s on coap gateway). After this the heartbeat system on my client was still receiving positive confirmation to my heartbeat packets. Meanwhile on the emqx broker the client was already terminated.

heartbeat (hex): 40030027b46d7174740a636f6e6e656374696f6e4d0b636c69656e7469643d3836303031363034303633323333380d03746f6b656e3d34303432353939303730 response (hex): 60440027 <= 2.04 response code

What did you expect to happen?

If the client was terminated from the gateway, then the gateway should respond with a reset response to my heartbeat packet not with an acknowledge + code 2.04 packet... received (hex): 60440027 <= acknowledge + 2.04 response code expected result(hex): 70440027 reset + 2.04 response code (with this it will notify that the client registration expired and it should reconnect to the server with a connection packet)

How can we reproduce it (as minimally and precisely as possible)?

Just send my pdu or any heartbeat packet to the broker... The coap gateway always responds with confirmation... (No prior connection registration is needed...)

Anything else we need to know?

If this is purely done as a broker ping status check functionality? Then why do I need to send client id and token? From my understanding this should be a heartbeat of the client-server connection status. Not a broker ping like behaviour...

EMQX version

```console $ ./bin/emqx_ctl broker sysdescr : EMQX version : 5.0.18 datetime : 1970-07-14T07:50:18.670241788+02:00 uptime : 23 minutes, 47 seconds ```

OS version

```console # On Windows: C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture BuildNumber Caption OSArchitecture Version 19044 Microsoft Windows 10 Home 64-bit 10.0.19044 ```

Log files

HJianBo commented 1 year ago

Hi @TomazCebekAstron Thanks for the report. We will try to fix it in the recent versions.

If this is purely done as a broker ping status check functionality? Then why do I need to send client id and token?

This is not intended as a check for the Broker alive status. Since EMQX maintains some resources for this client ID in connection mode, this heartbeat command is to tell the Broker that this CoAP client is still working and DON'T release the related resources.