Crash when committing data from transfer to new phone ("Foreign Key Constraints cannot be enabled or disabled while there are transactions in progress")
Crazywater opened this issue · 5 comments
- I have searched open and closed issues for duplicates
- I am submitting a bug report for existing functionality that does not work as intended
- I have read https://github.com/signalapp/Signal-Android/wiki/Submitting-useful-bug-reports
- This isn't a feature request or a discussion topic
Bug description
When transferring data to a new Phone, Signal crashes after the transfer completes. Reopening Signal on the new phone looks like a fresh install, but after going through the regular setup flow with a phone number and PIN the messages do appear.
The exception seems to be the following:
06-09 18:53:54.598 29507 29627 E AndroidRuntime: FATAL EXCEPTION: Thread-2
06-09 18:53:54.598 29507 29627 E AndroidRuntime: Process: org.thoughtcrime.securesms, PID: 29507
06-09 18:53:54.598 29507 29627 E AndroidRuntime: java.lang.IllegalStateException: Foreign Key Constraints cannot be enabled or disabled while there are transactions in progress. Finish all transactions and release all active database connections first.
06-09 18:53:54.598 29507 29627 E AndroidRuntime: at net.zetetic.database.sqlcipher.SQLiteConnectionPool.reconfigure(SQLiteConnectionPool.java:291)
06-09 18:53:54.598 29507 29627 E AndroidRuntime: at net.zetetic.database.sqlcipher.SQLiteDatabase.setForeignKeyConstraintsEnabled(SQLiteDatabase.java:2177)
06-09 18:53:54.598 29507 29627 E AndroidRuntime: at org.thoughtcrime.securesms.database.SignalDatabase$Companion.runPostBackupRestoreTasks(SignalDatabase.kt:300)
06-09 18:53:54.598 29507 29627 E AndroidRuntime: at org.thoughtcrime.securesms.database.SignalDatabase.runPostBackupRestoreTasks(Unknown Source:2)
06-09 18:53:54.598 29507 29627 E AndroidRuntime: at org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceServerTask.run(NewDeviceServerTask.java:52)
06-09 18:53:54.598 29507 29627 E AndroidRuntime: at org.signal.devicetransfer.NetworkServerThread.run(NetworkServerThread.java:97)
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: java.lang.IllegalStateException: Foreign Key Constraints cannot be enabled or disabled while there are transactions in progress. Finish all transactions and release all active database connections first.
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: at net.zetetic.database.sqlcipher.SQLiteConnectionPool.reconfigure(SQLiteConnectionPool.java:291)
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: at net.zetetic.database.sqlcipher.SQLiteDatabase.setForeignKeyConstraintsEnabled(SQLiteDatabase.java:2177)
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: at org.thoughtcrime.securesms.database.SignalDatabase$Companion.runPostBackupRestoreTasks(SignalDatabase.kt:300)
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: at org.thoughtcrime.securesms.database.SignalDatabase.runPostBackupRestoreTasks(Unknown Source:2)
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: at org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceServerTask.run(NewDeviceServerTask.java:52)
06-09 18:53:54.599 29507 29627 E SignalUncaughtException: at org.signal.devicetransfer.NetworkServerThread.run(NetworkServerThread.java:97)
Steps to reproduce
- Open a fresh Signal install on the new phone
- Go through the import flow on both phones
- Wait for copy to complete to 100% (>130k messages in my case)
Actual result: Copy completes but then Signal crashes immediately on the new phone
Expected result: Signal does not crash and data is successfully imported.
Screenshots
N/A
Device info
Device: Transferring from Moto G10 to Pixel 6a
Android version: Transferring from 11 to 13
Signal version: 6.21.3 on both devices
Link to debug log
Grabbed via ADB, attached as txt file:
logcat.txt
Update: Going through the regular setup flow after restarting Signal (confirming via SMS code and entering PIN) works, the messages seem to have been copied successfully.
I'm having a very similar issue, though the exact behavior depends on if I'm using a straight backup or a merge of two different backups (via signalbackup-tools)
With an unmerged backup, Signal crashes immediately after completing the backup but then lets me add my phone number and authenticate if I go through the restore flow again.
The behavior is exactly the same with the merged backup, except that with the merged backup, it enters a crash loop after authentication fails and the application never successfully starts.
I have run additional database checks on the merged backup and it did not show any issues.
The other thing I found, based on some other bug reports, was if I restore the backup in Airplane Mode, I do not get the initial crash. I can then turn off airplane mode to finish the activation flow. Unfortunately, even with this approach, the merged backup still causes a crash loop.
Device Info: Google Pixel 6a
Android Version: 13
Signal version: 6.21.3
Device Info 2: OnePlus N200
Android Version: 12
Signal version: 6.21.3
Crash log generated by running in airplane mode after a failed restore and then exporting the logs from inside the Signal App.
As @GraphiteSprite is pointing out there are several instances when foreign key constraints can't be disabled.
OP has it in SignalDatabase.runPostBackupRestoreTasks while @GraphiteSprite has it in FullBackupImporter.importFile:
06-30 06:34:12.390 13800 13960 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Foreign Key Constraints cannot be enabled or disabled while there are transactions in progress. Finish all transactions and release all active database connections first.
06-30 06:34:12.390 13800 13960 E AndroidRuntime: at net.zetetic.database.sqlcipher.SQLiteConnectionPool.reconfigure(SQLiteConnectionPool.java:291)
06-30 06:34:12.390 13800 13960 E AndroidRuntime: at net.zetetic.database.sqlcipher.SQLiteDatabase.setForeignKeyConstraintsEnabled(SQLiteDatabase.java:2177)
06-30 06:34:12.390 13800 13960 E AndroidRuntime: at org.thoughtcrime.securesms.backup.FullBackupImporter.importFile(FullBackupImporter.java:123)
This also looks like a hard to tackle problem to me, as it seems to happen only non deterministically...
The interesting bit in FullBackupImporter is that the transaction is closed beforehand:
db.endTransaction();
keyValueDatabase.endTransaction();
db.setForeignKeyConstraintsEnabled(true); // exception happening here
So this leaves to me basically following options:
- db.endTransaction() is not synchronous somehow
- db.endTransaction() is not sufficient as exception is mentioning "active" db connections to be closed
- There are other transactions still open
- Bug in SqlCipher
@greyson-signal What is your take on this problem?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to inactivity.