-
Notifications
You must be signed in to change notification settings - Fork 179
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
Losing messages in case of connection interrupt #569
Comments
OK, your points -
2.when reconnecting I don't get the messages that where sent after the connection broke as I have configured the connection with cleanStart = true Taking 2 first if you use clean start = true you will not get any retained messages as you have no session with the broker, if you do not clean start and use retained messages on reconnection you will get one message which will be the last one sent to your topic, i.e in your case your uptime topic, giving you the last know uptime state, then normal uptime messages will then resume. 1 is a little more complicated, the 15 seconds is not part of keep alive, from the log -
There is a 15 second gap between the raising of the exception and _startListening with no log output from the client, this is not the client doing this its the flutter runtime, why this is I don't know, after that you reconnect as normal. Other users have reported this before occasionally, that's why the client catches this exception and continues during autoreconnect so as to try and step over this. You will use all messages in this gap of course The autoreconnect sequence is not dependent on the keep alive mechanism between the client and the broker, you should be able to set client.keepAlivePeriod to any value you wish and the gap between the socket exception and reconnect will be whatever it happens to be in your use case, i.e. 15 seconds. In general suddenly taking the network down does affect different platforms in different ways, the client is event driven and can only react to this, if the flutter runtime doesn't generate any events then the client can't react, hence it can get out of step with what's really happening. Other users manage this by listening for these WIFI up/down events by using platform level events available to flutter then disconnecting the client manually on down events and reconnecting manually on up, autoreconnect is not enabled in these cases. Autoreconnect is a last ditch fairly blunt instrument designed for sudden network failure not for known events like turning on/off your WIFI. Hope this helps though this is a complicated area. |
Hi,
I'm trying to find the problem, why I sometimes lose messages. As it happens spuriously, I'm trying to understand it step by step. My first attempt is to make the connection as stable as possible. I'm afraid that this won't be the full solution but it would rule out connection problems.
Therefore, I built a very simple app that connects to my device and listens to the uptime topic (which is updated every second). Then I simulate a connection problem, by switching of the WiFi.
As you can see in the screenshot, I lose quite some messages during the connection problem.
I initialized the MQTT client with the following parameters.
And from now on, I only work with assumptions and it would be great if you could tell me if they are correct or wrong:
If these assumptions are correct, I can understand why I'm losing messages.
What I don't understand is why I'm getting an exception when the client tries to reconnect:
Unhandled Exception: SocketException: Connection reset by peer (OS Error: Connection reset by peer, errno = 54), address = 192.168.50.1, port = 53731
Here is the fragment of the log file with the reconnect:
Any help in understanding what's going on and how to get rid of the exceptions would be highly appreciated!
The text was updated successfully, but these errors were encountered: