-
Notifications
You must be signed in to change notification settings - Fork 523
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
[bug]The subscriber stop receiving messages because keepalive failed #506
Comments
The ping is sent if:
So your log does not contain enough information to assess whether the ping is being sent appropriately (given what is logged it looks like the last send was 15 seconds ago but I don't know what your keepalive interval was set to and the ping was sent before the section of log you included). As per the readme please attempt to provide a Minimal, Reproducible Example, or at a minimum the code you are using to connect, so I can see what options are set. This library has so many options that without knowing your configuration its impossible to assess issues. Note that, as per the readme, the most common cause of this kind of issue is when your handler is not returning in a timely manner (try setting
That is to be expected if you have set
This just turns off the keep alive; so yes it would prevent the issue occurring but does not really help (and with unreliable links keepalives are recommended). |
Hi, @MattBrittan , this is my source code. The main grountine sub the EMQ broker. The handler function will send the message to channel When get the message. Another grountine read the channel and insert the meesage to ClickHouse DB. The log has been attached. I recorded the time to insert the message into ClickHouse DB. You can see in the log file that it's almost always 60ms
|
So the ping is triggered here:
and time out occurs here:
You are using QOS=0 so the client does not send any response when a message is received. As mentioned above a PING is triggered when the This does means that if the only thing you are doing is to receive QOS0 messages then you should expect a PING to be sent fairly regularly. This check was added back in 2017 (in this commit) and appears in line with the spec requirement that:
Insufficient info; however if you are hammering the link with messages it's quite possible that the ping response will be delayed (you would need to check the broker logs to see if it received/responded to the request). Perhaps try increasing
Messages were received; but only ping checks:
You are using Cleansession = true (the default) so the broker will not remember your subscription (if you want it to call In summary I'm not seeing a bug here; everything seems to be operating as per the spec (but I don't know what is happening on the broker side in regards to responding to the PING). |
Hi @MattBrittan,Thank you for your help very mush. I will close this issues. |
What happend
I use the emqtt_bech https://github.com/emqx/emqtt-bench to create 100 publishers. These publishers sent messages to the test topic in parallel. Then use golang subscribe the topic and save the message to the databases.
However, subscriber will stop receving messages after running for some time.
What caused it?
I spent some time and found this bug might be caused by the keepalive.
paho.mqtt.golang/ping.go
Lines 26 to 28 in 8e87e5f
The function called by startCommsWorkers when the mqtt client's option KeepAlive is not 0.
paho.mqtt.golang/client.go
Line 525 in 8e87e5f
The keepalive function annotation said
Send ping when connection unused
. But it still send ping when my connection is in use. The ping resp failed sometimes under the a large number of parallel messages scenario. The mqtt client called stopCommsWorkers and reconnect to mqtt broker. But my subscriber's callback function never run again.How to testify
In order to prove my idea, I set the KeepAlive option to 0. And this bug seems solved.
Environment
golang: go version go1.14.2 linux/amd64
github.com/eclipse/paho.mqtt.golang v1.3.3
emqx: 4.2.5
The text was updated successfully, but these errors were encountered: