Signal-iOS icon indicating copy to clipboard operation
Signal-iOS copied to clipboard

Signal uses a very large amount of cellular data. 1MB+ and 80 background requests after receiving one text-only message with the app closed. Root cause appears to be Signal syncing a larger number of contacts with their attached photos to the Signal Desktop app every time it wakes up.

Open varenc opened this issue 8 years ago • 34 comments

  • [x] I have searched open and closed issues for duplicates
    • @866 is a similar old issue that I posted on, but was told to open a new issue
  • [x] I am submitting a bug report for existing functionality that does not work as intended
  • [x] This isn't a feature request or a discussion topic

Bug description

Signal uses a very high amount of celluar data. I observed 500MB in 8 days despite light usage. Obvious things like sending photos or long video chats are not happening. This celluar data seems to be consumed in the background and continues to grow even when the app is not opened for day.

Upon further testing with the Signal app closed I observed it making 80 requests and using 1MB+ of data in the background after recieving a text only message. I believe this behavior is the cause of the underlying high ceullar data usage problem.

Steps to observe 1MB+ of background data usage from one text-only message

Charles Proxy for iOS was used to observe background requests. I tried to MITM the traffic, but because Signal seems to use cert pinning MITMing fails and only the requests' domain and data usage can be observed.

Steps:

  • Tell a friend to msg me on Signal in 45 seconds
  • Close the Signal app on iOS (not move it to the background, but explicitly close it)
  • Open up the Charles Proxy and start intercepting
  • After the friend sends me a message, observe a new "itunes.apple.com" connection (from the Apple push notification service?) followed by requests to https://textsecure-service.whisphersystems.org
  • The requests to textsecure-service.whisphersystems.org continue for minutes, accumulating more and more data
  • In my testing over 80 requests are made. Charles only shows total session data usage but from watching it accumulate it's clear the majority of the data is associated with the Signal requests
  • Screenshot from soon after the message is sent image
  • Screenshot after waiting another minute image
  • The requests to textsecure-service.whisphersystems.org continued for another minute, but other iOS background activity complicated the session and I stopped taking screenshots
  • Eventually the Signal background requests stoped, and only then did Signal create a local iOS notification (that appears in Notification Center) informing me of the message

My guess is that something about my setup is exacerbating this issue. Here are some details that might be required to reproduce:

  • I have 2000+ contacts on my Phone
  • I estimate 300-400 contacts with phone numbers registered with Signal
  • I am a light user, only ever really talking with 5-6 individuals/groups
  • One group I'm in recieves ~100 messages per day on average. I've disabled notifications for this group, but my guess is that Signal still gets the push notifications from Apple and wakes up
  • I keep the Signal desktop app open most of the time on my desktop computer, but closed it for testing

Actual result: After 8 days I see 500MB of data usage. After 1 text-only message I saw 1MB+ of data usage and 80+ requests while the app was still closed.

Expected result: Signal should use less data after waking up from push notifications. Cumulatively, light text-only Signal usage should not lead to 500MB of cellular data usage in 8 days. I believe these issues are very related.

Device info

Device: iPhone X

iOS version: 11.3.1

Signal version: 2.29.2.4

Link to debug log

https://debuglogs.org/c36c1e303c2736fa76a3b89078ac28ebbc505a86832ab84bcea29df82cd43eb3.zip

varenc avatar Oct 26 '18 23:10 varenc

If details on the actual content of the background requests would be helpful just let me know.

I need to figure out some workaround for cert pinning. Possibly I could download the source code, disable pinning, then build and test that version...But perhaps you folks have a better alternative? Thanks!

varenc avatar Oct 26 '18 23:10 varenc

Thanks for the details, we'll definitely look into this.

One more question, can you tell me roughly how many people are in the groups you frequently contact?

michaelkirk-signal avatar Oct 27 '18 01:10 michaelkirk-signal

One group I'm gets a 3-8 messages per day and has 8 members. The other group has 12 members and gets up to ~100 messages a day, though the activity there is pretty irregular. The rest of the conversations from the last week are with individuals.

Thanks for looking at this!

varenc avatar Oct 27 '18 01:10 varenc

@varenc - are you on the beta by chance?

michaelkirk-signal avatar Oct 30 '18 23:10 michaelkirk-signal

Nope, I'm actually on the slightly older 2.29.2.4 version of Signal. I think I was on the Signal beta for the new desktop app awhile ago, but that desktop version now seems to be the default. Besides that have not been involved in any beta.

I can upgrade to the latest Signal version in the app store and try to reproduce again if you'd like, but I believe I've been experiencing this problem for awhile across many past versions so am not optimistic. If you don't have any theories on the cause of this though I'm happy to try.

varenc avatar Oct 31 '18 01:10 varenc

The beta includes some more detailed logging around attachment upload sizes, which could help diagnose the issue.

On Oct 30, 2018, at 19:45, Chris Varenhorst [email protected] wrote:

Nope, I'm actually on the slightly older 2.29.2.4 version of Signal. I think I was on the Signal beta for the new desktop app awhile ago, but the beta is now the default. Besides that have not been involved in any beta.

I can upgrade to the latest Signal version in the app store and try to reproduce again if you'd like, but I believe I've been experiencing this problem for awhile across many past versions so am not optimistic. If you don't have any theories on the cause of this though I'm happy to try.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

michaelkirk-signal avatar Oct 31 '18 13:10 michaelkirk-signal

@varenc @michaelkirk-signal

  • Is it possible to do the same logging for audio/video calls and voice messages?

  • Does the amount of data used depend on the WebRTC encoder (Opus, Vorbis, Apple Audio, etc.) configurations?

I checked on voice messages received from Android and iOS on Desktop, here is the MediaInfo for each:

from iOS:

Format : | MPEG-4 Format profile : | Apple audio with iTunes info Codec ID : | M4A (M4A /mp42/isom) File size : | 275 KiB Duration : | 15 s 720 ms Bit rate mode : | Constant Overall bit rate : | 143 kb/s

from Android:

Format : | ADTS Format/Info : | Audio Data Transport Stream Codec ID : | 2 File size : | 66.9 KiB Duration ~ 16s Bit rate mode : | Variable Overall bit rate ~ 35 kb/s

I wasn't able to check this for calls but there seems to be considerable difference in bit rates between iOS and Android.

xashyar avatar Nov 01 '18 21:11 xashyar

Hi Xashyar. I'm no expert on how the Signal devs do things, but I'd recommend making a separate issue for high audio/video data usage. That seems like it would have a separate cause since media was ruled out for the issue I'm reporting. I'm seeing high data usage when the app is closed but awaken by push notifications for text-only messages.

If you do open another issue, you could try to get some info using Charles Proxy like I did. You can track overall data usage and if media data uses a distinct domain you'll be able to see how much data just audio/video is using as well. It also sounds like you can switch to the Signal betas to enable extra logging, which might be helpful when you submit your debug logs.

varenc avatar Nov 02 '18 00:11 varenc

Also @michaelkirk-signal, would you like me to switch to the Signal iOS beta? With that, I can try to reproduce this problem again.

I believe switching to the iOS beta will delete the Signal app store app and my message history so I'd prefer not to, but if you think this might get you some valuable information just let me know and I'm happy to do it.

varenc avatar Nov 02 '18 00:11 varenc

The beta app installs just like an early update. So you can keep your messages.

But keep in mind, that as a beta, you are more susceptible to crashes and data loss.

On Nov 1, 2018, at 18:35, Chris Varenhorst [email protected] wrote:

Also @michaelkirk-signal, would you like me to switch to the Signal iOS beta? With that, I can try to reproduce this problem again.

I believe switching to the iOS beta will delete the Signal app store app and my message history so I'd prefer not to, but if you think this might get you some valuable information just let me know and I'm happy to do it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

michaelkirk-signal avatar Nov 03 '18 10:11 michaelkirk-signal

So I let Signal use cellular data for a few weeks and came back to this image

(again no voice calls or photo/media usage)

I just updated to the beta and reset cellular data usage tracking. Will report back if the high data usage continues (but my guess is it will)

varenc avatar Nov 20 '18 03:11 varenc

Thanks - now that you've updated to the beta, could you include a debug log with your next data usage report? There's some additional logging that might help narrow this down.

On Mon, Nov 19, 2018 at 9:14 PM Chris Varenhorst [email protected] wrote:

So I let Signal use cellular data for a few weeks and came back to this [image: image] https://user-images.githubusercontent.com/167585/48749307-3022b880-ec2f-11e8-96fb-38f11ceb8037.png

(again no voice calls or photo/media usage)

I just updated to the beta and reset cellular data usage tracking. Will report back if the high data usage continues (but my guess is it will)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/signalapp/Signal-iOS/issues/3962#issuecomment-440122459, or mute the thread https://github.com/notifications/unsubscribe-auth/AjQiwP1R1nA_xNCiOMBh8GDNF4j0V5vvks5uw3OMgaJpZM4X9GeW .

michaelkirk-signal avatar Nov 20 '18 15:11 michaelkirk-signal

Here's the latest debug report! I captured this right after reproducing high cellular data usage.

https://debuglogs.org/6a0e7389edac854b490de857522dc08bf247ea57605ae8d2ae9a93b92ca0b179.zip

Context: today I checked Signal celluar data usage and saw "only" 38MB in the last 18 hours or so. But to help test things I sent myself ~15 text only messages while the Signal app was closed and not on WiFi. After most messaged I opened it and then explicitly closed it so that the push notification would wake it up in the background. After sending these ~15 messages over the course of a couple minutes, my Signal cellular data usage jumped to 120MB from the 38MB it started with just minutes ago.

varenc avatar Nov 20 '18 19:11 varenc

for context, you can see in the logs that my tests begin around 11:47 of today. I used the Signal desktop app to send the messages to myself.

Note that it seems like Signal creates an iOS notification, but then quickly clears this so I only see it on my phone for less than a second. I'd speculate this happens because Signal creates an iOS notification for a new message, but then since it's a self-sent message it then quickly observes that the message is marked as seen and then clears the iOS notification. If the app was running in the background (because I didn't explicitly kill it) then I wouldn't see an iOS notification at all. My guess is that the high data usage is associated with a push notification starting the app up in the background when it's not running at all.

Also, there's a ~5-second delay between sending the message to myself and seeing the iOS notification. Not sure where this delay in being introduced, but this might be a result of all the work/bandwidth the app does on wake up. In my testing from awhile ago it seemed like this delay was even larger. I think the logs corroborate this in the time between application:didFinishLaunchingWithOptions: and application:didReceiveRemoteNotification but am not sure.

I think you can see a specific example of the app waking in the background at 2018/11/20 11:50:57:083 in my latest log. I believe that's Signal starting from a push notification. I then send myself a few messages, and then explicitly kill the app at 2018/11/20 11:51:11:613.

varenc avatar Nov 20 '18 20:11 varenc

Thanks for the details @varenc.

The new logging confirms that the large data usage, at least during your test period, is due to syncing your contacts with your Desktop instance. Signal does this automatically - on startup, periodically, and whenever your local contacts information changes to make sure you see up-to-date info on your desktop device.

Each of your contact syncs is about 32MB, which is quite a bit larger than I'd expect. Any ideas why that might be?

Do you have photos set for most of your contacts in your system contacts?

michaelkirk-signal avatar Nov 27 '18 17:11 michaelkirk-signal

Thanks for looking into this! You are indeed correct. I have a lot of contacts and a long time ago I had Facebook sync profile photos with my contacts so many of them do have photos associated with them. I find it rather useful that Signal shows me these and it makes the app friendlier and a bit more social.

It sounds like Signal is uploading these photos each time? Surely there must be some way to confirm that there's been no change to the photos and re-uploading isn't necessary? If avoiding re-uploading is a pain, perhaps just an option to disable contact photo syncing could be valuable for people like me.

Thanks again for investigating!

varenc avatar Nov 28 '18 01:11 varenc

@michaelkirk-signal, just wanted to follow up on this. Is there anything else I can do to help with this?

As another data point: In the last 7 days I've used the Signal iOS app for 13 minutes, but it has logged 1.6hrs of background activity. It must be spending a lot of time waking up and re-syncing the same contacts photos.

It sounds like removing my contact photos or stopping use of the Desktop app could be a workaround for now...but are there any others? I mainly use Signal on the Desktop so if there was just a way to turn off push notifications on my phone that'd be amazing, but I assume that would interfere with Desktop app usage? Alternatively, some way to turn off push notification/background wakes for certain group chats could really help. (local iOS notifications are already disabled, but I assume messages there still trigger background app wakes)

If any part of the solution here seems like a bug fix that's well suited to a new contributor, let me know! Scratching my own particular itch is very motivating...

varenc avatar Dec 05 '18 22:12 varenc

The case of having a 32MB contact sync is a bit of an outlier, so it hasn't yet become the single most important thing for us to work on. That said, having a ton of contacts and avatars is something we'd love to do a better job of supporting.

One way to help the process along as a contributor would be to add some debug logging around the statistics of the contact sync. e.g. how many contacts have avatars, how big is each avatar, whats a running total of the avatar sizes, etc.

A good entry point to start investigating the code would be here, where we build up the contact sync information: https://github.com/signalapp/Signal-iOS/blob/master/SignalServiceKit/src/Messages/DeviceSyncing/OWSSyncContactsMessage.m#L138

michaelkirk-signal avatar Dec 06 '18 17:12 michaelkirk-signal

on it! I got the Signal app running locally and have added some logging. So far just the avatar size. Oddly OWSLogging I add to "OWSSyncContactsMessage.m" isn't showing up in my xcode console, but I think that's because its listed under the Pods project instead of the Signal one? Any ideas how to see this log? But I can definitely see Signal syncing full avatar data everytime I set "Sync Contacts" in the debug UI! I think this is just updating the local contact database, so still fuzzy on how the Desktop app comes into play on this.

Stepping back a bit, I think the best fix would be to avoid syncing contact data to the desktop if there's been no changes. Is there any sort of contact freshness info or hash that already exists I could make use of? My guess is probably not. Alternatively I could potentially just look into something less elegant like only syncing avatar data to the desktop once per day. Not the ideal solution, but would definitely address the pain point. (Also I'd need to actual figure out how/where contacts are being uploaded to the desktop...)

That's getting a bit ahead of myself...for now I'm just going to try to just get some good logging in, figure out how to view the log output for something in the Pods project, and submit a small PR with just that!

varenc avatar Dec 13 '18 04:12 varenc

...

Stepping back a bit, I think the best fix would be to avoid syncing contact data to the desktop if there's been no changes. Is there any sort of contact freshness info or hash that already exists I could make use of? My guess is probably not. Alternatively I could potentially just look into something less elegant like only syncing avatar data to the desktop once per day. Not the ideal solution, but would definitely address the pain point. (Also I'd need to actual figure out how/where contacts are being uploaded to the desktop...) ...

Why not do some simple things like:

  1. Compare the avatar file size.
  2. Hash the avatar content.

... to see whether or not an update is required?

Also: are avatar file sizes limited in any way to avoid having someone with a crazy large avatar forcing a large amount of bandwidth transfer?

ngie-eign avatar Dec 13 '18 05:12 ngie-eign