Delayed/missing push messages
When messaging a friend of mine via push, most messages are delayed a few hours. Background data is enabled. Sometimes messages are even not delivered at all or arrive in different order than sent. This also happens with messages other people send him, although I can exchange messages with these people without problems (delivered within a few seconds). He runs a Nexus 5 with the latest stock Google Android and is perfectly reachable via Hangouts the whole time.
Any idea how to debug this?
I can confirm this problem, see #937. Please correct me: GCM works on a "best effort" basis. Messages can arrive at any time in any order. And it seems that this is not just an academic problem, it's actually happening.
We need some "server notices that a message has not been delivered and resend it" mechanism. Maybe possible with the delivery reports (#957)? Resending means, however, that the client would need a mechanism to deal with these duplicate messages (those would be two GCM messages; it would need to detect the duplicate content) - but he needs that anyway, see #937.
Issue #1029 may also be caused by this.
Edit: This was a user error. leaving the following up for reference.
I am having this issue as well, Alice's messages go through immediately to Bob, but Bobs messages get delayed/don't arrive (been testing for two days/a few hours), though they are shown as sent on Bobs phone. This happens with both phones on WiFi, and with both phones on mobile data.
This also caused a confusion of encrypted sessions that are ended "simultaneously" (during the delay), which led to lots of "bad encrypted message" errors, and the inability to reestablish a secure session.
This could only be solved by reinstalling the app. After reinstalling the delayed messages were delivered immediately (but as "bad encrypted messages" obviously).
Devices are Nexus 4 and Nexus 5 with stock Android.
This makes TextSecure push completely broken. Multi hour delays/delivery failures, while both parties are online, without the sender being notified is just the worst kind of broken for a communication program.
#1038 Might be related.
Having exactly the same problem as Certhas, for multiple days now. Everything works fine when forced to SMS-only, so the problem appears to be in the transport, rather than the app or the phone. Happy to provide any debugging, logs, etc if needed.
I too can confirm this, running on a HTC Desire Z with Android 2.3.3 and Textsecure 2.0.4
Messages arrive instantenously from Alice to Bob, but do not seem to arrive when send from Bob to Alice even though they are shown as sent. The initial key exchange works fine and also the exchange of encrypted messages via SMS works fine.
I would very much like to see this problem solved, since it prohibits me from spreading Textsecure among my friends.
Is the background of your messages blue also? It seems to be green if the mesage was actually received, but mine all have a blue background.
@Nordic89: Green messages are sent via SMS and blue messages are sent via push. As I described, everything works for SMS text messages, but push messages (the blue ones) only arrive immediately when sent from Alice to Bob and not when sent from Bob to Alice.
So in my case it turned out to be a user error. Alice had restrict background data on the google services app checked (the tricky bit being that it still transfers some data and thus doesn't actually display as restricted in the list of apps). Alice had not been using any chat applications but was relying on SMS before.
While this is a user error, it's fairly non-obvious. Some online tutorials online suggest doing this for privacy/data/battery reasons (as google services has been known to be buggy at times). Alice presumably did this without being aware that google services would have anything to do with delivering messages in a superficially unrelated SMS replacement app.
I don't know if this is technically possible, but it would be great if text secure could pop up a warning box if it detects that background services are restricted.
@behrmann Ah, that makes sense. My green messages always arrive and the blue ones don't, so it's definitely a problem with push messages.
@Certhas I'm not sure if that's possible to detect, but it'd be cool if you did some research to see whether there's an API for that and reported back.
The recommendation from ICS onward seems to be to use something like the following if you're running in the foreground or the background, but that's not really helpful unless it's TS code running. AFAICT it will take into account the global "Restrict background data" state, but I can't find any way to query it for a specific other app (like the @Certhas case of Google services being explicitly disallowed from using background data).
ConnectivityManager connectivityService = Context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = connectivityService.getNetworkActivityInfo();
if (network != null && network.isAvailable()) { // or network.isConnected() here
// background data should not be restricted
}
I wonder if this is another thing that can just be addressed by better messaging around the push transport (you need to have Play services/GCM running and able to access the network in the background, etc.).
Today it happened again to me: Yesterday evening I sent a push-messages to a colleague while his phone had no data connection. It was delivered about 10 hours later this morning.
I'm curious now: What service level does GCM offer? For example, does it guarantee delivery? What about caching, why does it take so long to deliver a message after a device regained network connectivity?
@wickedshimmy The problem is that I don't see how to differentiate between "no internet connection" and "background data restricted" with that code. Do you know if any of these checks explicitly only fails if background data is restricted?
No, that was sort of my point -- since ICS you can't. If you query the network state, you can get yes/no, but not why. Even the detailed info doesn't expose that setting on its own. That would work for either foreground or background services (if I can't send because the network isn't available, alert), but the problem specifically here is that the background play services isn't running any TS code, so there's no pace to make that check and warn what happened, and for cases like the above the availability can differ from app to app even with the same network info and permissions, so checking this ahead of time or from TS is also no good. There might be another API to use, but I don't think this one will work. Sorry for being unclear!
Is it confirmed now, that the Problem is with restricted background data? I just wonder, because I habe not restricted background data and habe both been the party to not receive PUSH messages and to send PUSH messages that have not been received (with two different communication partners).
I have confirmed that neither of the devices I'm having trouble with have restricted background data enabled. The one that is having the most trouble sending/receiving does wander through areas of reduced cell service, but still fails to send messages that are created once it's back in a good service area until much later, all with no indication to the sending user that the message has not been delivered.
I don't have background data restricted, yet still can't send any messages.
@Nordic89 can't you sent messages altogether or are they delayed heavily?
By the way: Restricting background data should never interfere with sending messages. If you can't send messages, something else is wrong...