njouanin / hbmqtt

MQTT client/broker using Python asynchronous I/O
MIT License
795 stars 188 forks source link

Broker: client reconnect keep-alive grows infinitely and client take over not implemented #220

Open kruton opened 3 years ago

kruton commented 3 years ago

It seems like if a client re-connects and a session is found in the cache, the timeout-disconnect-delay is added to the cached session's client_session.keep_alive. If the client keeps reconnecting, eventually it gets into very large values and causes some problems.

I think this is exacerbated because hbmqtt also doesn't appear to implement client take-over. Specifically it doesn't implement MQTT 3.1.1 section 3.1.4:

If the ClientId represents a Client already connected to the Server then the Server MUST disconnect the existing Client [MQTT-3.1.4-2].

Here are some recent logs that show the timeout keeps incrementing by the default timeout-disconnect-delay of 2:

2020-10-15 11:26:07,935   INFO     hbmqtt.broker: Connection from 10.100.10.1:65255 on listener 'tcp-ssl-1'
2020-10-15 11:26:08,205   DEBUG    hbmqtt.broker: Keep-alive timeout=12                                                                                                                                          
...
2020-10-15 11:26:45,360   INFO     hbmqtt.broker: Connection from 10.100.10.1:65256 on listener 'tcp-ssl-1'
2020-10-15 11:26:45,624   DEBUG    hbmqtt.broker: Found old session (Session(clientId=40285608b03f085d1b4e31ec5f60b3b912f64f2d, state=disconnected), <hbmqtt.mqtt.protocol.broker_handler.BrokerProtocolHandler object at 0x7f7cdfb299d0>)
2020-10-15 11:26:45,624   DEBUG    hbmqtt.broker: Keep-alive timeout=14 
...
2020-10-15 11:27:29,906   INFO     hbmqtt.broker: Connection from 10.100.10.1:65257 on listener 'tcp-ssl-1'
2020-10-15 11:27:30,167   DEBUG    hbmqtt.broker: Found old session (Session(clientId=40285608b03f085d1b4e31ec5f60b3b912f64f2d, state=disconnected), <hbmqtt.mqtt.protocol.broker_handler.BrokerProtocolHandler object at 0x7f7cdfb0dee0>)
2020-10-15 11:27:30,167   DEBUG    hbmqtt.broker: Keep-alive timeout=16  
...