signalapp / Signal-Desktop

A private messenger for Windows, macOS, and Linux.
https://signal.org/download
GNU Affero General Public License v3.0
14.6k stars 2.66k forks source link

Database startup error: Integrity check failed #3992

Open Mihahn opened 4 years ago

Mihahn commented 4 years ago

Bug Description

When I try to open Signal the following error message appears:

Database startup error:

Error: Integrity check failed: in database main Page 13696: btreeInitPage() returns error code 11 Page 21796: btreeInitPage() returns error code 11 at Object.initialize ([REDACTED]/app.asar/app/sql.js:1326:13) at async App. ([REDACTED]/app.asar/main.js:790:19)

Steps to Reproduce

I have some problems with shutdowns related to the known "Sleep Wake failure in EFI". This means the MacBook shuts down when it goes to deep sleep and there's an error message afterwards about the unexpected shutdown. It happened again yesterday evening and now I get this error message in Signal.

Actual Result:

I can't open Signal or recover the data.

Expected Result:

Signal should work fine of course

Platform Info

Signal Version: Can't tell, I guess the latest. Operating System: MacBook Pro 2012, MacOS 10.15.3 Linked Device Version: iPhone 7, 3.5.0.12

scottnonnenberg-signal commented 4 years ago

Unfortunately there aren't many options for a SQLCipher database which has been corrupted, since it has a lot more complexity than a normal SQLite database. This forum post points to some techniques you could use - attempt to repair it, or perhaps just attempt to extract as much data as you can: https://discuss.zetetic.net/t/need-help-integrity-check/2620

In theory you could dump the whole database, then make a new database with the same encryption key and import all that data, and things would just work.

Anyway, it would sure be nice if our infrastructure, SQLCipher/SQLite were resilient to unexpected shutdowns like your machine had, but such is not the case. At least right now.

paskalem commented 4 years ago

https://debuglogs.org/029fa63267a37d117beefcf2557b9b20628a6538fda274495aad918eecd7d2cc

scottnonnenberg-signal commented 4 years ago

@paskalem Debug logs with no context aren't very useful. Are you reporting a bug?

Mihahn commented 4 years ago

Thank you @scottnonnenberg-signal !

I "fixed" it by restoring the following files from TimeMachine Backup:

Of course it gave me a ton of "Error handling incoming message" notifications and writing a message to a contact using Desktop was shown as delivered (and actually delivered), but not synced to my iPhone or linked iPad.

Well: after resetting the session with Note to Self everything's working fine now and the messages from my Desktop appear on my iPhone/iPad and vice versa. I don't understand why resetting the session with Note to Self fixes the problem in all conversations, but it worked. [EDIT: It didn't!]

Is there any (security) problem with this method?

scottnonnenberg-signal commented 4 years ago

@Mihahn No security issues with what you've done, aside from encryption errors between you and anyone you had spoken to from that desktop instance (including your primary phone) since the backup was taken. 'Reset session' will fix things, as you've discovered. You can also unlink this restored desktop instance with your phone and re-link, and that will act as a 'Reset session' for all of your contacts at once.

Mihahn commented 4 years ago

@Mihahn No security issues with what you've done, aside from encryption errors between you and anyone you had spoken to from that desktop instance (including your primary phone) since the backup was taken. 'Reset session' will fix things, as you've discovered. You can also unlink this restored desktop instance with your phone and re-link, and that will act as a 'Reset session' for all of your contacts at once.

Thank you! But when I unlink the restored desktop instance, won't this delete all data? How should I do this without deleting the messages?

And I didn't have to reset the session with every contact; when I reset the session in "Note to Self" it worked for another contact, too. I don't know why, but it did and it's working fine so far.

scottnonnenberg-signal commented 4 years ago

@Mihahn When you choose to unlink a desktop device from your phone, the messages are still left intact. Encryption information is deleted when a desktop device discovers that it is unlinked, but the messages and contacts remain.

The reason that the reset session 'worked for other contacts' is because when you send a message to a contact, you also send a 'sync message' to your other devices which is then used to replicate that sent message. So if the communication between your phone and your desktop instance is broken, that sync message cannot be sent.

Mihahn commented 4 years ago

That said people having this error message could generally do those steps to get Signal Desktop working again without losing all their message history (except for those messages between backup and restore)?

Edit: @scottnonnenberg-signal I have to take back what I said yesterday, it's not working for all contacts. Of course you are right, I had to reset the session for every single contact!

One more question: you said I could unlink the Desktop without losing messages to reset the sessions for all contacts. How can I link the Desktop afterwards again? I'm a bit afraid to unlink and not being able to link again afterwards. Can I unlink and link again and keep all messages?

josh-signal commented 4 years ago

@Mihahn yup you should be able to. There's a dialog that pops up that'll ask you to relink and then you use your primary device to scan the code and link. You shouldn't be losing messages if you keep the stuff in Library/Application Support/Signal.

edit: If you don't see the relink dialog appear immediately you can restart the app to force it to show up.

Mihahn commented 4 years ago

@Mihahn yup you should be able to. There's a dialog that pops up that'll ask you to relink and then you use your primary device to scan the code and link. You shouldn't be losing messages if you keep the stuff in Library/Application Support/Signal.

edit: If you don't see the relink dialog appear immediately you can restart the app to force it to show up.

Thanks, worked like charm! Now everything's fine again - but hopefully Signal will be able to manage those sudden restarts in some future release ;-)

tamsky commented 3 years ago

I hit this same issue due to a corrupt point-in-time Time Machine snapshot of the db. Thank you for the instructions above here - they helped me restore an older snapshot folder + unlink/link to get it working again.

It would be nice (but possibly also wishful thinking) if Signal (via the SQLite Backup API) could play nicely together with TM and quiesce/sync the db during each backup.

tnafziger commented 3 years ago

I "fixed" it by restoring the following files from TimeMachine Backup:

  • Library/Application Support/Signal

Thanks @Mihahn , this worked for me. I only needed to restore Library/Application Support/Signal and then was able to relink my desktop to my phone app (as a new device) and I was back up and running.

Tip: If you can't find the correct correct signal folder on your machine (I was looking in the root rather than under my user) just search for db.sqlite on your mac to find where the correct Signal folder (in Application support) is.