signalapp / Signal-Desktop

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

MainSQL close, failed: SqliteError: file is not a database #7039

Closed CoSoCo closed 1 month ago

CoSoCo commented 1 month ago

Using a supported version?

Overall summary

After duplicating the files of the Signal configuration, the App shows an error. Signal Datenbankfehler Additionally, copying the error doesn't work.

This is on Ubuntu 22.04

Steps to reproduce

  1. user dir (HOME) is: /home/user
  2. From live media create new one with sudo mkdir /home/user_new and sudo chown user:user /home/user_new
  3. make hard-linked copies of any relevant data including Signal data with e.g. sudo cp -al /home/user/.config/Signal /home/user_new/.config/
  4. renaming: /home/user -> /home/user_old /home/user_new -> /home/user So in result all files are the same as cause of hard links.
  5. Start the machine as normal
  6. Start Signal Desktop

When I rename back the user dirs, then Signal Desktop runs again properly.

Why it doesn't run from the hard linked copy?

Expected result

Signal Desktop should run properly.

Actual result

From terminal:

$ signal-desktop
Set Windows Application User Model ID (AUMID) { AUMID: 'org.whispersystems.signal-desktop' }
NODE_ENV production
NODE_CONFIG_DIR /opt/Signal/resources/app.asar/config
NODE_CONFIG {}
ALLOW_CONFIG_MUTATIONS undefined
HOSTNAME T500
NODE_APP_INSTANCE undefined
SUPPRESS_NO_CONFIG_WARNING undefined
SIGNAL_ENABLE_HTTP undefined
userData: /home/ich/.config/Signal
config/get: Successfully read user config file
config/get: Successfully read ephemeral config file
making app single instance
libva error: /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so init failed
{"level":30,"time":"2024-10-04T17:50:20.622Z","msg":"got fast localeOverride setting null"}
{"level":30,"time":"2024-10-04T17:50:20.623Z","msg":"app.ready: hour cycle preference: UnknownPreference"}
{"level":30,"time":"2024-10-04T17:50:20.623Z","msg":"app.ready: preferred system locales: de-DE, de"}
{"level":30,"time":"2024-10-04T17:50:20.624Z","msg":"locale: Supported locales: af-ZA, ar, az-AZ, bg-BG, bn-BD, bs-BA, ca, cs, da, de, el, en, es, et-EE, eu, fa-IR, fi, fr, ga-IE, gl-ES, gu-IN, he, hi-IN, hr-HR, hu, id, it, ja, ka-GE, kk-KZ, km-KH, kn-IN, ko, ky-KG, lt-LT, lv-LV, mk-MK, ml-IN, mr-IN, ms, my, nb, nl, pa-IN, pl, pt-BR, pt-PT, ro-RO, ru, sk-SK, sl-SI, sq-AL, sr, sv, sw, ta-IN, te-IN, th, tl-PH, tr, ug, uk-UA, ur, vi, yue, zh-CN, zh-HK, zh-Hant"}
{"level":30,"time":"2024-10-04T17:50:20.633Z","msg":"locale: Preferred locales: de-DE, de"}
{"level":30,"time":"2024-10-04T17:50:20.634Z","msg":"locale: Locale Override: null"}
{"level":30,"time":"2024-10-04T17:50:20.637Z","msg":"locale: Matched locale: de"}
{"level":40,"time":"2024-10-04T17:50:20.904Z","msg":"intl.onWarn [@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution"}
{"level":30,"time":"2024-10-04T17:50:20.905Z","msg":"locale: Text info direction for de: ltr"}
{"level":30,"time":"2024-10-04T17:50:20.909Z","msg":"getSQLKey: decrypting key"}
{"level":30,"time":"2024-10-04T17:50:20.923Z","msg":"getSystemTraySetting got value DoNotUseSystemTray"}
{"level":30,"time":"2024-10-04T17:50:20.923Z","msg":"getSystemTraySetting returning DoNotUseSystemTray"}
{"level":30,"time":"2024-10-04T17:50:20.935Z","msg":"app ready"}
{"level":30,"time":"2024-10-04T17:50:20.935Z","msg":"starting version 7.27.0"}
{"level":30,"time":"2024-10-04T17:50:20.935Z","msg":"media access status [object Undefined] [object Undefined]"}
{"level":30,"time":"2024-10-04T17:50:20.945Z","msg":"got fast theme-setting value system"}
{"level":30,"time":"2024-10-04T17:50:21.014Z","msg":"got fast theme-setting value system"}
{"level":30,"time":"2024-10-04T17:50:21.023Z","msg":"got fast spellcheck setting true"}
{"level":30,"time":"2024-10-04T17:50:21.025Z","msg":"visibleOnAnyScreen(window): x=69, y=247, width=965, height=790"}
{"level":30,"time":"2024-10-04T17:50:21.025Z","msg":"visibleOnAnyScreen(display #10217761556922432): x=0, y=0, width=1680, height=1050"}
{"level":30,"time":"2024-10-04T17:50:21.025Z","msg":"Initializing BrowserWindow config: {\"show\":false,\"width\":965,\"height\":790,\"minWidth\":300,\"minHeight\":200,\"autoHideMenuBar\":false,\"titleBarStyle\":\"default\",\"backgroundColor\":\"#3a76f0\",\"webPreferences\":{\"devTools\":false,\"spellcheck\":true,\"enableBlinkFeatures\":\"CSSPseudoDir,CSSLogical\",\"enablePreferredSizeMode\":true,\"nodeIntegration\":false,\"nodeIntegrationInWorker\":false,\"sandbox\":false,\"contextIsolation\":true,\"preload\":\"[REDACTED]/preload.wrapper.js\",\"backgroundThrottling\":true,\"disableBlinkFeatures\":\"Accelerated2dCanvas,AcceleratedSmallCanvases\"},\"icon\":\"[REDACTED]/images/signal-logo-desktop-linux.png\",\"x\":69,\"y\":247}"}
{"level":30,"time":"2024-10-04T17:50:21.272Z","msg":"spellcheck: user locales: [\"de-DE\",\"de\"]"}
{"level":30,"time":"2024-10-04T17:50:21.276Z","msg":"spellcheck: available spellchecker languages: [\"af\",\"bg\",\"ca\",\"cs\",\"cy\",\"da\",\"de\",\"de-DE\",\"el\",\"en\",\"en-AU\",\"en-CA\",\"en-GB\",\"en-GB-oxendict\",\"en-US\",\"es\",\"es-419\",\"es-AR\",\"es-ES\",\"es-MX\",\"es-US\",\"et\",\"fa\",\"fo\",\"fr\",\"fr-FR\",\"he\",\"hi\",\"hr\",\"hu\",\"hy\",\"id\",\"it\",\"it-IT\",\"ko\",\"lt\",\"lv\",\"nb\",\"nl\",\"pl\",\"pt\",\"pt-BR\",\"pt-PT\",\"ro\",\"ru\",\"sh\",\"sk\",\"sl\",\"sq\",\"sr\",\"sv\",\"ta\",\"tg\",\"tr\",\"uk\",\"vi\"]"}
{"level":30,"time":"2024-10-04T17:50:21.276Z","msg":"spellcheck: setting languages to: [\"de-DE\",\"de\"]"}
2024-10-04 19:50:22.383: ERROR CORE sqlcipher_page_cipher: hmac check failed for pgno=1
2024-10-04 19:50:22.383: ERROR CORE sqlite3Codec: error decrypting page 1 data: 1
2024-10-04 19:50:22.383: ERROR CORE sqlcipher_codec_ctx_set_error 1
{"level":40,"time":"2024-10-04T17:50:22.384Z","msg":"MainSQL: Database log code=26: file is not a database in \"PRAGMA journal_mode = WAL\""}
{"level":30,"time":"2024-10-04T17:50:22.384Z","msg":"MainSQL: migrateDatabase: Migration without cipher change failed"}
2024-10-04 19:50:22.536: ERROR CORE sqlcipher_page_cipher: hmac check failed for pgno=1
2024-10-04 19:50:22.536: ERROR CORE sqlite3Codec: error decrypting page 1 data: 1
2024-10-04 19:50:22.536: ERROR CORE sqlcipher_codec_ctx_set_error 1
{"level":40,"time":"2024-10-04T17:50:22.536Z","msg":"MainSQL: Database log code=26: statement aborts at 2: [PRAGMA user_version] file is not a database"}
{"level":50,"time":"2024-10-04T17:50:22.537Z","msg":"MainSQL: Database startup error: SqliteError: file is not a database\n    at Database.pragma ([REDACTED]/node_modules/@signalapp/better-sqlite3/lib/methods/pragma.js:11:31)\n    at getUserVersion ([REDACTED]/ts/sql/util.js:132:13)\n    at migrateSchemaVersion ([REDACTED]/ts/sql/Server.js:406:54)\n    at openAndMigrateDatabase ([REDACTED]/ts/sql/Server.js:438:5)\n    at openAndSetUpSQLCipher ([REDACTED]/ts/sql/Server.js:460:14)\n    at initialize ([REDACTED]/ts/sql/Server.js:507:10)\n    at MessagePort.<anonymous> ([REDACTED]/ts/sql/mainWorker.js:69:41)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)\n    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)"}
{"level":50,"time":"2024-10-04T17:50:22.538Z","msg":"Failed to get zoom factor {\"name\":\"SqliteError\"}"}
{"level":30,"time":"2024-10-04T17:50:23.388Z","msg":"got fast theme-setting value system"}
{"level":50,"time":"2024-10-04T17:50:24.806Z","msg":"sql.initialize was unsuccessful; returning early"}
{"level":30,"time":"2024-10-04T17:50:24.810Z","msg":"close event {\"readyForShutdown\":false,\"shouldQuit\":false}"}
{"level":30,"time":"2024-10-04T17:50:24.811Z","msg":"maybeRequestCloseConfirmation: Checking to see if close confirmation is needed"}
{"level":50,"time":"2024-10-04T17:51:44.993Z","msg":"onDatabaseError: Quitting application"}
{"level":30,"time":"2024-10-04T17:51:45.003Z","msg":"main window closed event"}
{"level":30,"time":"2024-10-04T17:51:45.005Z","msg":"quit event {\"hasEventBeenPrevented\":false,\"windowCount\":0,\"mainWindowExists\":false}"}
{"level":50,"time":"2024-10-04T17:51:45.015Z","msg":"Error occurred in handler for 'sql-channel:read': {\"name\":\"SqliteError\"}"}
{"level":50,"time":"2024-10-04T17:51:45.017Z","msg":"maybeRequestCloseConfirmation: Response never received; continuing with close."}
{"level":50,"time":"2024-10-04T17:51:45.018Z","msg":"MainSQL close, failed: SqliteError: file is not a database\n    at Database.pragma ([REDACTED]/node_modules/@signalapp/better-sqlite3/lib/methods/pragma.js:11:31)\n    at getUserVersion ([REDACTED]/ts/sql/util.js:132:13)\n    at migrateSchemaVersion ([REDACTED]/ts/sql/Server.js:406:54)\n    at openAndMigrateDatabase ([REDACTED]/ts/sql/Server.js:438:5)\n    at openAndSetUpSQLCipher ([REDACTED]/ts/sql/Server.js:460:14)\n    at initialize ([REDACTED]/ts/sql/Server.js:507:10)\n    at MessagePort.<anonymous> ([REDACTED]/ts/sql/mainWorker.js:69:41)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)\n    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)"}

app.log main.log

Screenshots

No response

Signal version

Not possible to get from the app, because of the error, but with apt policy signal-desktop I get 7.27.0

Operating system

Ubuntu 22.04

Version of Signal on your phone

No app on phone

Link to debug log

No response

ayumi-signal commented 1 month ago

Hi, this sounds like a DB encryption key decryption error. To store the decryption key, we use electron safeStorage which uses a keyring backend (such as gnome libsecret or kwallet). Based on the commands you listed it seems like it should work, but I'm not sure where the keyring is stored and it's required to decrypt the key.

On Linux a possible workaround is to skip the encrypted db key by using the command line flag --password-store="basic" (for details see https://www.electronjs.org/docs/latest/api/safe-storage#safestoragegetselectedstoragebackend-linux). Note this will only affect a fresh run of the app, and will not decrypt an existing encrypted db key, and you must continue to run the app with this command line flag.

CoSoCo commented 1 month ago

Based on the commands you listed it seems like it should work, but I'm not sure where the keyring is stored and it's required to decrypt the key.

Thanks for your hints. I now tried to find such a missing keyring, but was not successful. As you can see from the inode numbers, all files are identical in old and current HOME dir.\

$ find ../old/ -iname "*keyring*" -exec ls -ali {} \;
insgesamt 56
656672 drwx------ 2 ich ich  4096 Okt  4 13:28 .
656671 drwx------ 5 ich ich  4096 Apr 26  2017 ..
669198 -rw------- 2 ich ich 17835 Okt  4 13:28 login.keyring
657421 -rw------- 4 ich ich 10093 Dez 29  2020 login.keyring.temp-1839844398
657421 -rw------- 4 ich ich 10093 Dez 29  2020 login.keyring.temp-1898464673
656960 -rw------- 2 ich ich   207 Jun 13  2013 user.keystore
657421 -rw------- 4 ich ich 10093 Dez 29  2020 ../old/.gnome2/keyrings/login.keyring.temp-1898464673
657421 -rw------- 4 ich ich 10093 Dez 29  2020 ../old/.gnome2/keyrings/login.keyring.temp-1839844398
669198 -rw------- 2 ich ich 17835 Okt  4 13:28 ../old/.gnome2/keyrings/login.keyring
657735 -rw-r----- 1 ich ich 108 Feb 28  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.1.gz
662806 -rw-r----- 1 ich ich 108 Feb  1  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.7.gz
675588 -rw-r----- 1 ich ich 109 Sep 24  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.2.gz
657889 -rw-r----- 1 ich ich 108 Feb 23  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.3.gz
670403 -rw-r----- 1 ich ich 108 Feb 10  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.5.gz
673207 -rw-r----- 1 ich ich 109 Sep 14  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.4.gz
675628 -rw-r----- 1 ich ich 109 Sep 25  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.1.gz
673484 -rw-r----- 1 ich ich 109 Aug  3  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.6.gz
671087 -rw-r----- 1 ich ich 108 Feb  5  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.6.gz
671081 -rw-r----- 1 ich ich 108 Feb 11  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.4.gz
675574 -rw-r----- 1 ich ich 109 Sep 23  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.3.gz
673942 -rw-r----- 1 ich ich 109 Sep 14  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.5.gz
673971 -rw-r----- 1 ich ich 109 Aug  2  2018 ../old/.cache/upstart/gnome-keyring-ssh.log.7.gz
658325 -rw-r----- 1 ich ich 108 Feb 28  2016 ../old/.cache/upstart/gnome-keyring-gpg.log.2.gz

ich@T500:~$ find . -iname "*keyring*" -exec ls -ali {} \;
insgesamt 56
230719 drwx------ 2 ich ich  4096 Okt  5 11:36 .
230718 drwx------ 5 ich ich  4096 Apr 26  2017 ..
669198 -rw------- 2 ich ich 17835 Okt  4 13:28 login.keyring
657421 -rw------- 4 ich ich 10093 Dez 29  2020 login.keyring.temp-1839844398
657421 -rw------- 4 ich ich 10093 Dez 29  2020 login.keyring.temp-1898464673
656960 -rw------- 2 ich ich   207 Jun 13  2013 user.keystore
657421 -rw------- 4 ich ich 10093 Dez 29  2020 ./.gnome2/keyrings/login.keyring.temp-1898464673
657421 -rw------- 4 ich ich 10093 Dez 29  2020 ./.gnome2/keyrings/login.keyring.temp-1839844398
669198 -rw------- 2 ich ich 17835 Okt  4 13:28 ./.gnome2/keyrings/login.keyring
insgesamt 16
131350 drwx------  2 ich ich 4096 Okt  5 11:29 .
131338 drwxrwxr-x 39 ich ich 4096 Okt  5 11:28 ..
131352 -rw-------  1 ich ich 1208 Okt  5 11:29 login.keyring
131354 -rw-------  1 ich ich  207 Sep 28 01:41 user.keystore
131352 -rw------- 1 ich ich 1208 Okt  5 11:29 ./.local/share/keyrings/login.keyring

$ find ../old/ -iname "*wallet*" -exec ls -ali {} \;
923505 -rw-rw-r-- 1 ich ich 4100 Jul  2  2018 ../old/.cache/gnome-software/icons/15b0c38ccb8183cec8603033ef52e561a716728d-lindacoin-wallet1.png
750477 -rw------- 2 ich ich 59 Mär  4  2019 ../old/.config/kwalletrc
787979 -rw------- 1 ich ich 48 Mai 28  2014 ../old/.kde/share/config/kwalletrc
insgesamt 8
812767 drwx------ 2 ich ich 4096 Jan 12  2018 .
788221 drwx------ 9 ich ich 4096 Jan 12  2018 ..
insgesamt 20
747510 drwxrwxr-x  2 ich ich 4096 Mai 14  2019 .
656675 drwxr-xr-x 77 ich ich 4096 Okt  4 15:54 ..
665897 -rw-------  2 ich ich  713 Mai 14  2019 kdewallet.kwl
747601 -rw-------  2 ich ich   16 Mär  8  2019 kdewallet.kwl.h11555
657109 -rw-r--r--  2 ich ich   56 Jul  1  2018 kdewallet.salt
657109 -rw-r--r-- 2 ich ich 56 Jul  1  2018 ../old/.local/share/kwalletd/kdewallet.salt
665897 -rw------- 2 ich ich 713 Mai 14  2019 ../old/.local/share/kwalletd/kdewallet.kwl
747601 -rw------- 2 ich ich 16 Mär  8  2019 ../old/.local/share/kwalletd/kdewallet.kwl.h11555

ich@T500:~$ find . -iname "*wallet*" -exec ls -ali {} \;
750477 -rw------- 2 ich ich 59 Mär  4  2019 ./.config/kwalletrc
787979 -rw------- 2 ich ich 48 Mai 28  2014 ./.kde/share/config/kwalletrc

insgesamt 8
139682 drwx------ 2 ich ich 4096 Jan 12  2018 .
139672 drwx------ 9 ich ich 4096 Jan 12  2018 ..
insgesamt 20
148742 drwxrwxr-x  2 ich ich 4096 Mai 14  2019 .
131338 drwxrwxr-x 39 ich ich 4096 Okt  5 15:18 ..
665897 -rw-------  2 ich ich  713 Mai 14  2019 kdewallet.kwl
747601 -rw-------  2 ich ich   16 Mär  8  2019 kdewallet.kwl.h11555
657109 -rw-r--r--  2 ich ich   56 Jul  1  2018 kdewallet.salt
657109 -rw-r--r-- 2 ich ich 56 Jul  1  2018 ./.local/share/kwalletd/kdewallet.salt
665897 -rw------- 2 ich ich 713 Mai 14  2019 ./.local/share/kwalletd/kdewallet.kwl
747601 -rw------- 2 ich ich 16 Mär  8  2019 ./.local/share/kwalletd/kdewallet.kwl.h11555

Do you have any idea, where the keyring could be?

One interesting thing is, there is no ./.local/share/keyrings/ in the old HOME. But when I rename it, I'm asked to create a new keyring when starting signal-desktop.

CoSoCo commented 1 month ago

I now found out that I had to re-login into the desktop, after deleting ./.local/share/keyrings/. Now Signal Desktop runs again fine.

So to recover the history from old HOME dir, the following must be copied:

  1. cp -al /home/old/.config/Signal /home/user/.config/
  2. cp -al /home/old/.gnome2/keyrings /home/user/.gnome2/
  3. and if present, remove rm /home/user/.local/share/keyrings/
  4. then re-login

Alternatively, the legacy location /home/old/.gnome2/keyrings can be moved to the new location /home/user/.local/share/keyrings, but then new keys in the latter, if existing, become overwritten / deleted.