-
Notifications
You must be signed in to change notification settings - Fork 100
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
DefaultPinger doesn't detect connection loss when consistently sending packets #288
Comments
Interesting. In this situation I'd expect the loss of connection to be picked when an attempt is made to write to (or, generally, read from) the connection. I think there might be a small bug here; At QOS 0 we:
but at QOS 1/2 we don't call Generally I'd also expect the connection loss to be picked in The ping process exists to detect half-open connections; sending a packet should be enough to detect this (should get a TCP timeout) so I don't believe that an additional ping is needed in this case. I do test this and the connection loss is picked up in that situation, so what is happening in your case must vary. I'd appreciate it if you could share more information about how you are using the library (i.e. are you using |
I'm using QOS1 and autopaho. I'll try to get you code and logs tomorrow. From what I understand the TCP timeout can take up to 15 minutes to detect a dead connection. gRPC fixed a similar issue by setting TCP_USER_TIMEOUT on the socket on Linux: |
Don't worry too much about this (as you are using If you have time, try chucking a |
Partially redacted log messages: Code for how we create the paho client:
|
Interesting, it's not what I suspected (there is no indication in the log that the loss of connection has been detected). This seems to be an issue with the TCP stack (would generally expect the loss of connection to be noted). The MQTT Spec only requires the client to send a PING when the gap between outgoing packets exceeds the Keep Aliveperiod. This is what this library currently does. I've taken a look at other libraries. The Go paho.mqtt.golang v3.1.1 client sends a ping based on both sent and received packets, as do the python and c clients. As such, I think it would be reasonable for this library to take the same approach to catch this kind of issue. Happy to receive a PR for this, otherwise I'll try to have a look within a couple of weeks. |
Describe the bug
When a TCP connection is lost (for instance, when switching between wifi networks) the
DefaultPinger
doesn't detect the issue or re-establish the connection.This happens because
DefaultPinger
calculates thepingDue
time based onlastPacketSent
. When packets are consistently being sent (but no replies are ever received) theDefaultPinger
keeps delaying it's ping message indefinitely.To reproduce
Establish an MQTT connection, send messages on a more frequent cadence than
keepAlive
, and then disrupt the TCP connection.Debug output
Expected behaviour
DefaultPinger
should detect the lost network connection and re-establish the MQTT connection.Software used:
github.com/eclipse/paho.golang v0.21.0
Additional context
The text was updated successfully, but these errors were encountered: