-
Notifications
You must be signed in to change notification settings - Fork 162
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
When the application is not used in the background, I get the error of falling into disconnect after a certain period of time #584
Comments
Please help me. I'm trying to get the project up to my deadline. I need to settle this matter before my boss gets angry :' |
Modern versions of Android don't allow apps to run continuously in the background. It's expected that the OS stops your connections once the OS decides to go to sleep or deems your app idle/in standby/using too many resources/etc. You will find more info if you search for "Android background restrictions" on your preferred search engine. Note that over time, the OS has added more and more restrictions. Some helpful links from the official documentation: Either way, your issue is unrelated to this library, in my opinion. |
I also get the error when I use the library repo directly. I know about background restrictions etc. The services I have written survive, but hiveMq breaks the mqtt connection by itself. |
@gelbertgel Did you ever get anywhere on this issue? I think I'm experiencing the same issue. I'm running it in a Foreground Service with unrestricted battery access but when the phone is locked or goes to sleep I am getting a disconnect essentially after every message sent. |
This message indicates that the TCP connection was killed or terminated:
On a positive note, the MQTT protocol was designed with intermittent connections so if you set session expiry correctly, when the client reconnects, the session state will be restored. If you have to still do work when the app is closed or the screen is locked, that is a setting with Android as @bddckr pointed out. If needed, here are a couple blog posts that explain session expiry:
Since this issue doesn't apply to this client, I'll close this out. If you think this is incorrect, let me know. If you find a solution, please let us know as it may help future Android developers. |
🐛 Bug Report
No error is received when the device is actively used, disconnect error is received when the screen is locked or the device is not used for a certain period of time.
🔬 How To Reproduce
Steps to reproduce the behavior:
Code sample
Log:
onDisconnected(MqttClientDisconnectedContext arg0)] com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT.
Environment
Hardware or Device? Device
What version of this client are you using? Android 9,10,11,12,13 -> All android devices
Operating System? Android
Which MQTT protocol version is being used? Mqttv5
Which MQTT broker (name and version)? Mosquitto v2.0.15
The text was updated successfully, but these errors were encountered: