Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client does not disconnect from broker if keepalive ping gets no response (heartbeat timeout) #157

Open
srijan opened this issue May 11, 2022 · 2 comments

Comments

@srijan
Copy link

srijan commented May 11, 2022

The purpose of keepalive is to periodically send a ping packet (and check for it's response) so that both sides of the connection know when the connection fails, and they can close the old connection and try to connect again.

In the current implementation, emqtt sends the PINGREQ packet at keepalive intervals (if configured), but does not check that PINGRESP is coming correctly. So, in case the connection breaks / hangs, emqtt does not fail.

How to reproduce:

  1. Run emqtt on local system and connect to emqx (or any other broker) running on cloud with keepalive = 10 seconds (or any low value).
  2. Disconnect from WiFi/Network ( or simulate connection hang in some other way )
  3. emqtt does not give connection failure even after several minutes

Expected behavior: If no ping response is received from broker after keepalive*3 seconds, disconnect from broker. Then the retry logic can try to reconnect, if configured.

The actual heartbeat timeout value can also be created as a config similar to emqx's keepalive_backoff.

@srijan srijan changed the title Client does not disconnect from broker if keepalive ping gets no response Client does not disconnect from broker if keepalive ping gets no response (heartbeat timeout) May 11, 2022
@srijan
Copy link
Author

srijan commented May 11, 2022

My recommended implementation:

  1. Keep track of last packet received time for any packet in a new state variable.
  2. Start a new timer which checks this last packet received time periodically
  3. If last packet received time > Keepalive * backoff * 2, then consider the connection failed.

If this is acceptable, I can raise a PR. Comments welcome.

@emiltin
Copy link

emiltin commented Jan 17, 2024

I see the same: After a disconnect, there is no disconnect notice/error from the emqtt lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants