-
PapaTutuWawa
Quick question: Due to reasons I had to implement my own XMPP library for my mobile XMPP client and it works great. However, after some time (unsure about the exact time), my connection just silently stops working and I cannot send or receive data. I don't receive any stream errors; it just stops. This happens although I send pings either by requesting an XEP-0198 ack or by just sending a whitespace ping every 5 minutes. Is there anything else I need to do to stop this from happening?
-
Ge0rG
PapaTutuWawa: what platform is your moblie client running on?
-
PapaTutuWawa
Android. But the thing is that the system is not killing the app as I keep viewing logs on my PC and I log every ping I send
-
Zash
Obscure socket timeout? What does the server logs say?
-
Ge0rG
PapaTutuWawa: did you request an exception from battery optimizations?
-
Ge0rG
PapaTutuWawa: when you connect the device via USB that might also change power saving behavior
-
PapaTutuWawa
Ge0rG: I didn't because I thought that having no exception would just kill the foreground service entirely, which I would notice
-
PapaTutuWawa
Zash: I'll have to timeout again, but I think that my prosody just said that the connection timed out
-
Ge0rG
PapaTutuWawa: IIRC it will just freeze the app instead
-
flow
PapaTutuWawa, do you receive pongs to your xmpp pings?
-
PapaTutuWawa
That would still be weird as I can still see the service trying to send a ping to the server even after no data can come in or go out
-
PapaTutuWawa
flow: When I used only 0198 pings, then after some point: no. But until then I did. But I still think that 2h at max until I have to reconnect is a bit short, or am I mistaken?
-
flow
PapaTutuWawa, i suspect your TCP connection became stale than, could be due to various reasions
-
flow
I believe modern Android's even suspend TCP connections of more-or-less inactive non-foreground apps, but it could be also just a middlebox or dozen other things that causes the tcp connection to become stale
-
PapaTutuWawa
flow: I didn't know that. I'll try it then
-
flow
PapaTutuWawa, try what?
-
PapaTutuWawa
Setting a battery optimization exception for my app if it's true that Android suspends TCP connections for inactive apps
-
PapaTutuWawa
Sorry for being unclear😅️
-
flow
PapaTutuWawa, I doubt that this alone will help
-
flow
at least for the latest android versions, which basically force you to use a foreground service for long-lived TCP connections like XMPP uses
-
flow
besides that, my recommendation for years has been to act on CONNECTIVITY_CHANGED broadcasts from Android, and have a mechansim to swiftly check if the connection is still alive, based on xep199 pings with a low timeout (say less than 30, 20, or 15 seconds)
-
flow
if that check fails, forcefully tear down the XMPP connection and restablish it, ideally using stream mangement
-
PapaTutuWawa
It seems like my prosody closes the connection with a "timeout during receiving"