Signal Crashes on Backup Import (OOM)
- [X] I have searched open and closed issues for duplicates
- [X] I am submitting a bug report for existing functionality that does not work as intended
- [X] I have read https://github.com/signalapp/Signal-Android/wiki/Submitting-useful-bug-reports
- [X] This isn't a feature request or a discussion topic Possibly related to: https://github.com/signalapp/Signal-Android/issues/9136
Bug description
Restoring a backup that is 11.4GB in size causes Signal to crash (OOM)
Steps to reproduce
Create a backup Import backup on a separate device
Actual result: Application crashes Expected result: Messages to appear on new device
Device info
Device: Google Pixel 4 Android version: 10.0 Signal version: 4.49.14
Link to debug log (Not able to get debug log because do not have the option on first import. Below is LogCat
11-02 20:03:25.258 12377 12430 E AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
11-02 20:03:25.258 12377 12430 E AndroidRuntime: Process: org.thoughtcrime.securesms, PID: 12377
11-02 20:03:25.258 12377 12430 E AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at android.os.AsyncTask$4.done(AsyncTask.java:399)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:271)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.lang.Thread.run(Thread.java:919)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: Caused by: java.lang.OutOfMemoryError: Failed to allocate a 874830208 byte allocation with 4116870 free bytes and 508MB until OOM, target footprint 8233742, growth limit 536870912
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at org.thoughtcrime.securesms.backup.FullBackupImporter$BackupRecordInputStream.readFrame(FullBackupImporter.java:3)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at org.thoughtcrime.securesms.backup.FullBackupImporter$BackupRecordInputStream.readFrame(FullBackupImporter.java:1)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at org.thoughtcrime.securesms.backup.FullBackupImporter.importFile(FullBackupImporter.java:4)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at org.thoughtcrime.securesms.registration.fragments.RestoreBackupFragment$2.doInBackground(RestoreBackupFragment.java:7)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at org.thoughtcrime.securesms.registration.fragments.RestoreBackupFragment$2.doInBackground(RestoreBackupFragment.java:1)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at android.os.AsyncTask$3.call(AsyncTask.java:378)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
11-02 20:03:25.258 12377 12430 E AndroidRuntime: ... 4 more
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger:
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: java.lang.RuntimeException: An error occurred while executing doInBackground()
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at android.os.AsyncTask$4.done(AsyncTask.java:399)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.util.concurrent.FutureTask.run(FutureTask.java:271)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.lang.Thread.run(Thread.java:919)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: Caused by: java.lang.OutOfMemoryError: Failed to allocate a 874830208 byte allocation with 4116870 free bytes and 508MB until OOM, target footprint 8233742, growth limit 536870912
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at org.thoughtcrime.securesms.backup.FullBackupImporter$BackupRecordInputStream.readFrame(FullBackupImporter.java:3)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at org.thoughtcrime.securesms.backup.FullBackupImporter$BackupRecordInputStream.readFrame(FullBackupImporter.java:1)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at org.thoughtcrime.securesms.backup.FullBackupImporter.importFile(FullBackupImporter.java:4)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at org.thoughtcrime.securesms.registration.fragments.RestoreBackupFragment$2.doInBackground(RestoreBackupFragment.java:7)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at org.thoughtcrime.securesms.registration.fragments.RestoreBackupFragment$2.doInBackground(RestoreBackupFragment.java:1)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at android.os.AsyncTask$3.call(AsyncTask.java:378)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
11-02 20:03:25.259 12377 12430 E UncaughtExceptionLogger: ... 4 more
11-02 20:03:25.270 1316 14159 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
11-02 20:03:25.271 1316 2542 W ActivityTaskManager: Force finishing activity org.thoughtcrime.securesms/.registration.RegistrationNavigationActivity
11-02 20:03:25.295 12377 12430 I Process : Sending signal. PID: 12377 SIG: 9
11-02 20:03:25.295 1316 1350 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
11-02 20:03:25.295 1316 1350 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
11-02 20:03:25.321 1316 8698 I WindowManager: WIN DEATH: Window{f7d94ee u0 org.thoughtcrime.securesms/org.thoughtcrime.securesms.registration.RegistrationNavigationActivity}
11-02 20:03:25.321 1316 2096 I ActivityManager: Process org.thoughtcrime.securesms (pid 12377) has died: vis+99 TOP
11-02 20:03:25.321 1316 1352 I libprocessgroup: Successfully killed process cgroup uid 10228 pid 12377 in 0ms
11-02 20:03:25.322 1316 1735 W InputDispatcher: channel 'f7d94ee org.thoughtcrime.securesms/org.thoughtcrime.securesms.registration.RegistrationNavigationActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
11-02 20:03:25.322 1316 1735 E InputDispatcher: channel 'f7d94ee org.thoughtcrime.securesms/org.thoughtcrime.securesms.registration.RegistrationNavigationActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
11-02 20:03:25.322 793 793 I Zygote : Process 12377 exited due to signal 9 (Killed)
11-02 20:03:25.323 1316 8698 W InputDispatcher: Attempted to unregister already unregistered input channel 'f7d94ee org.thoughtcrime.securesms/org.thoughtcrime.securesms.registration.RegistrationNavigationActivity (server)'
Caused by: java.lang.OutOfMemoryError
With a backup file that large I can imagine why. On many devices that will probably give an out of storage space error.
In this case, if you still have access to both devices and have root, you could try this approach: https://community.signalusers.org/t/howto-manual-backup-restore-if-full-backup-does-not-work/2462
I don't have root, but thanks for the input.
To clarify, I have successfully restored backups of this size on previous versions. I agree with the storage comment, however I have a 128gb device. Secondly, an OOM error seems to me like the import function within signal is not cleaning up messages as they are processed. I haven't yet checked the source code so I don't know how it is being done, but it would be silly to try and pull everything from disk into memory.
I deleted most messages and brought the file size down to 5gb and still get the error.
I should first note I am not a java programmer (but do have quite a bit of knowledge on the backup format).
The backup file consists of a series of frames, each preceded by a 4 byte number indicating the size of the following frame in bytes. The debug log shows the program is trying to allocate over 800MB of memory on this line. Apparently, the four-byte frame header says the next frame is going to be 834MB, and then that amount of memory is allocated to read the next frame into (tried to be allocated anyway, it obviously fails). As far as I know, no frame is ever supposed to be that large. The size of attachments isn't even included in this number, but even if that was the case, this is well over the maximum attachment size.
Anyway. I have no solution, just thought I'd share my thoughts on this problem. That is, it is not a memory cleanup problem (Java does not have any way of cleaning up memory, the VM is supposed to do that automatically). It seems like this four byte header is somehow incorrect in your backup file. I would normally say the file was just corrupted somehow, but you seem to be able to reproduce this, so now I don't know how this could happen.
Not able to get debug log because do not have the option on first import. Below is LogCat
You can now actually, tap any title on any registration page 8 times.
I'm running into this on a device replacement workflow. The problem is as described, I have a 10.3GB restore file that I'm not able to transfer to a replacement device. This is problematic because I have to return the replaced device in a timely manner and will lose physical access to the original in the next week. Signal no longer supports an "any time" import - it's at registration or nothing currently. This means the person in this situation only has the choice to start over and lose everything (years of Signal messages, pictures, conversations, etc). Is this at all prioritized or have an ETA or beta build we could test to get this moving? Having a broken migration process seems to be a huge blocker. Thank you!
To say it's "broken" is perhaps oversimplifying it. Backups largely work, and I've been through many backup-restore flows on various occasions with an 8+ GB backup file. But there are cases where either the backup file itself, or the reading of the backup file, gets into a bad state.
I once experienced a bad backup restore (with an identical OOM stack trace) that was a result of a bad file copy. Simply copying the same file over a second time fixed things. I would try that first.
However, there are situations where re-copying doesn't work, and we have to figure out if that's because of an error during writing or during reading. These are tricky to debug because we can't recreate the issue, and for obvious reasons we can't ask for the backup files of affected users.
I may be able to create a build that has extremely verbose logging, but I'd have to take some time to figure out what that logging would be.
Thanks @greyson-signal. I tried twice last night - but let me move the file off the original device in a different way. Thanks for the response! If I can't get it to go I'll hop back and see if we can work out the detailed debug build. Much appreciated.
@greyson-signal I validated the hash of the backup on the source phone and also on the destination phone. Both match, Signal crashes as it approaches the end of the restore. Is there any way to get an extended debug build or grab the debug from the initial onboarding as it stands?
Thanks!
Hey guys, i have the same problem with the current version and a backup of round about 550 MB.
Please find my logs at debuglogs.com
If I can provide more information, feel free to ask!
@greyson-signal Could this have something to do with the change to avatars to use recipientId instead of 'name'?
I notice in the exporter that the avatar write function (https://github.com/signalapp/Signal-Android/blob/master/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java#L326) sets .setRecipientId(avatarName) (which used to be setName() before the change), but the 'avatarName' that is used in that call is (unchanged since before the migration): outputStream.write(avatar.getName(), new FileInputStream(avatar), avatar.length()); (https://github.com/signalapp/Signal-Android/blob/master/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java#L101). So it seems to me, the old name (eg "+31601234567") is used as the recipientid. The backup importer does check if the avatar in the backup 'hasRecipientId()', but I assume this evaluates to true simply because 'setRecipientId()' was used to set the old name.
Anyway, I haven't tested this extensively, but that's just my guess from reading the code. Also, from personal experience I know the Avatar frames are (almost) the last frames written to the backup file which would explain why nearly everyone (here and in the closed duplicates) encounter this issue when the restoration is nearly complete. Lastly, the recipientid migration is just simply the only change to the backup exporter between now and before the troubles started.
I do have the same problem with a 600 MB backup. I created a backup with the latest release, 4.49.18, and tried to restore it with the very same version. Here the crash also happens right at the end of the restore.
@bepaald I very much appreciate the research, but the code you're referencing is being misinterpreted.
https://github.com/signalapp/Signal-Android/blob/master/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java#L101
The avatar.getName() here references the filename, which while it used to be a phone number, is now a recipientId. That happens in AvatarMigrationJob.java, which is migration that was put in place around the same time the backup exporter was changed.
Lastly, the recipientid migration is just simply the only change to the backup exporter between now and before the troubles started
If we're being honest, this issue has cropped up from time to time for quite a while. I am trying to determine if this represents an uptick in occurrences, and it's hard to say. Regardless, I am trying to at least get more debugging in place.
Yes, I was just about to post to say to disregard my previous comment. I had come to the same conclusion.
I have been following the backup restoration bugs quite closely for the last while, and helped quite a few people (mostly in #8355, but also on the community forums and through other channels) fix their broken backups. I do feel that there is a bit of an increase in the bug reports lately, especially the wrong frame size. In fact, I have seen the wrong frame size only once before (and my program was able to fix that backup as well), but maybe it is just becoming a more prominent manifestation of the same problem now that the import ignores the bad MAC (which precedes it in multiple of these reports).
Anyway, I apologize for the noise, maybe one of my backups will finally go bad one of these days, then hopefully I'll be able to help a bit better :)
@greyson-signal I hate to ask, but I am under a time constraint and have to send back an RMA phone. The user I'm transferring the old Signal database cannot switch to a new phone without the old messages. I'm curious if there's any indication of what the bug is and if there's any way for me to help test? Otherwise I will have the person send back the new phone until this issue is resolved. Thank you!
Edit: I just started looking at @bepaald tooling and will give that a shot to see if I can fix the backup. Is there any reason I should have the end user move to Signal beta that would potentially help get this reimported?
I created a new backup on the old phone using a new key. It produced the same result.
https://debuglogs.org/7ef5ad3dfb5abda321a1f361556619d43c3eb029bda058ba48fe81706944c186
So this seems somehow reproducible.
@greyson-signal I hate to ask, but I am under a time constraint and have to send back an RMA phone. The user I'm transferring the old Signal database cannot switch to a new phone without the old messages. I'm curious if there's any indication of what the bug is and if there's any way for me to help test? Otherwise I will have the person send back the new phone until this issue is resolved. Thank you!
Edit: I just started looking at @bepaald tooling and will give that a shot to see if I can fix the backup. Is there any reason I should have the end user move to Signal beta that would potentially help get this reimported?
You can copy the old file over to your new phone. Navigate to /Internal Storage/Signal/Backups or /sdcard/Signal/Backups on your old phone. Then just make sure you have a copy of the key and you should be fine, you'll have to use the default SMS on the new device temporarily, but once they fix the bug you should be able to restore
You can copy the old file over to your new phone. Navigate to /Internal Storage/Signal/Backups or /sdcard/Signal/Backups on your old phone. Then just make sure you have a copy of the key and you should be fine, you'll have to use the default SMS on the new device temporarily, but once they fix the bug you should be able to restore
That's assuming the problem is with backup file reading, not the way that backup files are created.
You can copy the old file over to your new phone. Navigate to /Internal Storage/Signal/Backups or /sdcard/Signal/Backups on your old phone. Then just make sure you have a copy of the key and you should be fine, you'll have to use the default SMS on the new device temporarily, but once they fix the bug you should be able to restore That's assuming the problem is with backup file reading, not the way that backup files are created.
True, but I don't even want to think of that as a possibility >.<
I am seeing the same issue with a 256mb backup file. Crashes at end of restore
Debug log submitted
https://debuglogs.org/641ea4ebda03a6f6e54ad37ccb1c311494cf63fdcf4f80d888efc3642f06749c
@davidjmeier I'd be very curious to hear the results. Please realize that it's hard to deal with all different possible unexpected bytes in an invalid backup file. It is very possible that the program does not fix this particular problem (yet!). Also, since I've never had a bad backup file myself (apart from a few handcrafted ones), supporting new types of broken backups depends on a back-and-forth of reporting results and running new custom builds of the program to get more information. This could be quite a long process.
Having said that, I am fairly confident I can fix nearly any broken backups. I've done the normal ones, with just 1 bad MAC, but also one where the bad MAC was followed by a bad framesize (which is what's happening to most people in this bug report). If all else fails, I've even generated a working backup for an user who had accidentally truncated the last gigabyte off the end of his backup file. So that should be a bit of an assurance that the program can restore at least anything before the corruption (which seems to be close to the end of the file for most people here).
Anyway, just wanted to say good luck and feel free to tell me the results or ask for help.