deltachat / deltachat-desktop

Email-based instant messaging for Desktop.
GNU General Public License v3.0
950 stars 170 forks source link

Crash when trying to go back from "Add Account" or "Delete Account" on Microsoft Store version #3959

Open WofWca opened 5 months ago

WofWca commented 5 months ago

This works fine on a manually downloaded 1.46.1, which is also built from 899f196d. Note that the manually installed one is 32 bit, and the Mircosoft Store is 64. Idk if this matters.

Here I clicked "Add Account" at 08:43:00, then clicked "back" at 08:44:09, then "back" again at 08:46:00, then "back" again at 08:49:00, then "Let's get started" at 08:49:19, after which the crash occurs:

2024-06-19T08:42:36.599Z    core/event              INFO    ""  1   "src/scheduler.rs:674: IMAP session supports IDLE, using it."
2024-06-19T08:42:36.662Z    core/event              INFO    ""  1   "src/imap/idle.rs:64: INBOX: Idle entering wait-on-remote state"
2024-06-19T08:43:00.709Z    core/event              INFO    ""  64  "src/sql/migrations.rs:950: Created new database; [migration] v68-v114"
2024-06-19T08:43:00.710Z    core/event              INFO    ""  64  "src/sql.rs:294: Opened database \"C:\\\\Users\\\\wofwc\\\\AppData\\\\Local\\\\DeltaChat\\\\accounts\\\\redacted-aaaaaaaa-aaaaaaa-aaaaaaa\\\\dc.db\"."
2024-06-19T08:43:00.724Z    renderer/stores/SettingsStore   INFO    ""  "cleared settings store"
2024-06-19T08:43:00.731Z    core/event              INFO    ""  1   "src/scheduler.rs:108: stopping IO"
2024-06-19T08:43:00.733Z    core/event              INFO    ""  1   "src/scheduler.rs:826: Shutting down SMTP loop."
2024-06-19T08:43:00.769Z    core/event              INFO    ""  1   "src/scheduler.rs:429: shutting down inbox loop"
2024-06-19T08:43:00.774Z    core/event              WARNING ""  64  "src/context.rs:465: can not start io on a context that is not configured"
2024-06-19T08:43:00.774Z    renderer/ScreenController   INFO    ""  "system_info"   {"arch":"64","deltachat_core_version":"v1.140.2","level":"awesome","num_cpus":"redacted","sqlite_version":"redacted"}
2024-06-19T08:43:00.777Z    renderer/ScreenController   INFO    ""  "account_info"  {"arch":"64","redacted":"redacted","blobdir":"C:\\Users\\me\\AppData\\Local\\DeltaChat\\accounts\\redacted-aaaaaaaa-aaaaaaa-aaaaaaa\\dc.db-blobs","redacted": "redacted","database_dir":"C:\\Users\\me\\AppData\\Local\\DeltaChat\\accounts\\redacted-aaaaaaaa-aaaaaaa-aaaaaaa\\dc.db"}
2024-06-19T08:43:01.775Z    main/state              INFO    ""  "Saving state to C:\\Users\\me\\AppData\\Local\\DeltaChat\\config.json"
2024-06-19T08:44:09.278Z    renderer/stores/SettingsStore   INFO    ""  "cleared settings store"
2024-06-19T08:44:10.286Z    main/state              INFO    ""  "Saving state to C:\\Users\\me\\AppData\\Local\\DeltaChat\\config.json"
2024-06-19T08:45:10.567Z    renderer/components/OnboardingScreen    ERROR   "\ni (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/components/screens/WelcomeScreen/OnboardingScreen.tsx:53:13)"   "unexpected error type" {"code":-1,"message":"failed to remove account data\n\nCaused by:\n    The process cannot access the file because it is being used by another process. (os error 32)"}
2024-06-19T08:45:10.569Z    renderer                ERROR   "\nfile:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/App.tsx:109:10"    "Unhandled Rejection:"  {"isTrusted":true}  {"code":-1,"message":"failed to remove account data\n\nCaused by:\n    The process cannot access the file because it is being used by another process. (os error 32)"}
2024-06-19T08:46:00.000Z    renderer/components/OnboardingScreen    ERROR   "\ni (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/components/screens/WelcomeScreen/OnboardingScreen.tsx:53:13)"   "unexpected error type" {"code":-1,"message":"account with id 64 doesn't exist anymore"}
2024-06-19T08:46:00.001Z    renderer                ERROR   "\nfile:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/App.tsx:109:10"    "Unhandled Rejection:"  {"isTrusted":true}  {"code":-1,"message":"account with id 64 doesn't exist anymore"}
2024-06-19T08:49:00.488Z    renderer/components/OnboardingScreen    ERROR   "\ni (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/components/screens/WelcomeScreen/OnboardingScreen.tsx:53:13)"   "unexpected error type" {"code":-1,"message":"account with id 64 doesn't exist anymore"}
2024-06-19T08:49:00.488Z    renderer                ERROR   "\nfile:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/App.tsx:109:10"    "Unhandled Rejection:"  {"isTrusted":true}  {"code":-1,"message":"account with id 64 doesn't exist anymore"}
2024-06-19T08:49:19.612Z    renderer/react-crashhandler ERROR   "\nhf.componentDidCatch (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/components/screens/CrashScreen.tsx:17:9),\nhf.o.componentDidCatch.n.callback (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:217:345),\nEg (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:131:408),\nYi (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:220:84),\nb (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:259:160),\nNf (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/scheduler/cjs/scheduler.production.min.js:18:343),\ngg (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:122:325),\ndr (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:252:279)"   "The app encountered an react error"    {"stack":"Error: no context selected\n    at selectedAccountId (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/ScreenController.tsx:365:11)\n    at c (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/src/renderer/components/helpers/ClickableLink.tsx:13:21)\n    at Ch (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:157:137)\n    at ck (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:267:460)\n    at bk (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:250:347)\n    at ak (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:250:278)\n    at Tj (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:250:138)\n    at c (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:243:163)\n    at b (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:123:115)\n    at Lt.unstable_runWithPriority (file:///C:/Program%20Files/WindowsApps/merlinux.DeltaChat_1.46.1.0_x64__v2ry5hvxhdhyy/app/resources/app.asar/node_modules/scheduler/cjs/scheduler.production.min.js:18:343)","message":"no context selected"}

The manually installed version's log (where everything works fine):

024-06-19T08:19:50.124Z core/event              INFO    ""  1   "src/imap/idle.rs:64: INBOX: Idle entering wait-on-remote state"
2024-06-19T08:20:00.676Z    core/event              INFO    ""  62  "src/sql/migrations.rs:950: Created new database; [migration] v68-v114"
2024-06-19T08:20:00.677Z    core/event              INFO    ""  62  "src/sql.rs:294: Opened database redacted
2024-06-19T08:20:00.687Z    renderer/stores/SettingsStore   INFO    ""  "cleared settings store"
2024-06-19T08:20:00.693Z    core/event              INFO    ""  1   "src/scheduler.rs:108: stopping IO"
2024-06-19T08:20:00.695Z    core/event              INFO    ""  1   "src/scheduler.rs:826: Shutting down SMTP loop."
2024-06-19T08:20:00.710Z    core/event              INFO    ""  1   "src/scheduler.rs:429: shutting down inbox loop"
2024-06-19T08:20:00.713Z    core/event              WARNING ""  62  "src/context.rs:465: can not start io on a context that is not configured"
2024-06-19T08:20:00.713Z    renderer/ScreenController   INFO    ""  "system_info"   {"arch":"32","deltachat_core_version":"v1.140.2","level":"awesome",redacted
2024-06-19T08:20:00.716Z    renderer/ScreenController   INFO    ""  "account_info"  {"arch":"32",redacted
2024-06-19T08:20:01.713Z    main/state              INFO    ""  "Saving state to C:\\Users\\me\\AppData\\Local\\DeltaChat\\config.json"
2024-06-19T08:20:09.263Z    renderer/stores/SettingsStore   INFO    ""  "cleared settings store"
2024-06-19T08:20:09.299Z    core/event              INFO    ""  1   "src/chat.rs:4316: Device-message changelog-version-1.46.0-version1 already added."
2024-06-19T08:20:09.311Z    core/event              INFO    ""  1   "src/scheduler.rs:67: starting IO"
2024-06-19T08:20:09.319Z    renderer/ScreenController   INFO    ""  "system_info"   {"arch":"32","deltachat_core_version":"v1.140.2","level":"awesome",redacted
2024-06-19T08:20:09.319Z    core/event              INFO    ""  1   "src/scheduler.rs:389: starting inbox loop"
2024-06-19T08:20:09.323Z    core/event              INFO    ""  1   "src/imap.rs:333: Connecting to IMAP server"
2024-06-19T08:20:09.330Z    core/event              INFO    ""  1   "src/location.rs:747: Location loop is waiting for 24h 0m 0s or interrupt"
2024-06-19T08:20:09.338Z    core/event              INFO    ""  1   "src/scheduler.rs:752: Starting SMTP loop."
2024-06-19T08:20:09.339Z    renderer/ScreenController   INFO    ""  "account_info"  {"arch":"32",redacted
2024-06-19T08:20:09.339Z    core/event              INFO    ""  1   "src/scheduler.rs:914: scheduler is running"
2024-06-19T08:20:09.348Z    core/event              INFO    ""  1   "src/smtp.rs:694: Selected rows from SMTP queue: []."
2024-06-19T08:20:09.349Z    core/event              INFO    ""  1   "src/smtp.rs:799: Sending MDNs."
2024-06-19T08:20:09.349Z    core/event              INFO    ""  1   "src/contact.rs:1841: Recently seen loop waiting for 0h 4m 34s or interrupt"
2024-06-19T08:20:09.350Z    core/event              INFO    ""  1   "src/scheduler.rs:787: SMTP fake idle started."
2024-06-19T08:20:09.351Z    core/event              INFO    ""  1   "src/scheduler.rs:815: SMTP has no messages to retry, waiting for interrupt."
2024-06-19T08:20:09.352Z    core/event              INFO    ""  1   "src/net.rs:72: Resolved redacted
2024-06-19T08:20:09.353Z    core/event              INFO    ""  1   "src/ephemeral.rs:582: Ephemeral loop waiting for deletion in 24h 0m 0s or interrupt"
redacted
2024-06-19T08:20:10.311Z    main/state              INFO    ""  "Saving state to C:\\Users\\me\\AppData\\Local\\DeltaChat\\config.json"
redacted
2024-06-19T08:20:10.694Z    core/event              INFO    ""  1   "src/imap/idle.rs:64: INBOX: Idle entering wait-on-remote state"
2024-06-19T08:20:25.872Z    main/menu               INFO    ""  "rebuilding menu with locale ru"

It appears like Core hangs on first "back" click, then on second click it tries to access the file but fails. But it's just my intuition. After the first "back" click it doesn't take much CPU time.

This is not a recent regression. I have been noticing this for a while, at least from 1.44, maybe earlier.

Simon-Laux commented 5 months ago

The process cannot access the file because it is being used by another process.

windows again (with its only one process can have a file handle at a time rule)... maybe we can just tell core to schedule it for deletion if it gets this error on windows, or somehow force that it become the sole process opening these files?

But now the interesting question would be what files are accessed, I guess blob files, but I'm not sure.

nicodh commented 4 months ago

Any progress on this?

WofWca commented 4 months ago

Not from me. It looks to me like it requires some core knowledge, which I don't have too much of.

link2xt commented 4 months ago

We have try_many_times workaround that we tried to remove at some point and then restored in https://github.com/deltachat/deltachat-core-rust/pull/4873 again because Windows CI failed due to the database not being closed. Now Delta Chat core tries to remove the folder 60 times for a minute, but apparently with microsoft store setup it is still not enough.

We should probably remove this try_many_times and find actual reason the database stays open for some time after the context is dropped.

There was also an old issue discussing similar problem: https://github.com/deltachat/deltachat-core-rust/issues/2695

On desktop the error can be ignored, worst case the database remains on disk but it is a small unconfigured database. Core does not garbage-collect accounts folder, maybe we should do it as well to get rid of such databases that we failed to delete.

I also opened core issue: https://github.com/deltachat/deltachat-core-rust/issues/5809

link2xt commented 4 months ago

I made a fix for the core: https://github.com/deltachat/deltachat-core-rust/pull/5814 Probably best thing to do now is to update the core to include this fix.

gerryfrancis commented 4 months ago

Basically this is how Windows works: Files stored in the Program Files (sub)folder(s) are protected by user access control (UAC) in a way only an elevated user (who has applied for administrator rights before) is allowed to write into. The above log of the Microsoft Store version of Delta Chat does not seem to write to the current user profile (path C:\Users\[current user]), but into the app folder instead, which is, what I believe, must not be permitted during runtime.

Edit: After looking into the log again, I have recognized that the database has been located in the user profile anyway, so mea culpa, and have a nice day!

nicodh commented 2 months ago

Seems to be fixed in current release. Tested on Windows 10.

WofWca commented 2 months ago

1.46.7 ? Nope, still buggy. Are you using the MS Store version?

nicodh commented 2 months ago

Yes. Ok I will uninstall and reinstall to make sure the sandbox paths are used...

WofWca commented 2 months ago

@nicodh Could you please clarify the current state of the issue, if you know off the top of your head? It doesn't affect fresh Microsoft Store installs, but affects all users who at some point had installed the Setup.exe version? Or just the ones who at some point had a pre- 1.46.7 installation?

nicodh commented 2 months ago

I just tried a fresh install in a "fresh" Windows 10 install. The files are in sandbox and a the bug is not reproducable. If you had previously installed via Setup.exe even an install from store will save the data in AppData/Local...

Can you still reproduce it? Where is your data stored?

WofWca commented 2 months ago

Mine is in \AppData\Local\DeltaChat, and yes 1.46.8 (git: v1.33.0-989-g5018d9d4) from Microsoft Store still hangs and crashes.

nicodh commented 2 months ago

Ok then we have to investigate further. The path only can't be the problem. I tested Store installs with both paths.

WofWca commented 1 month ago

Here are fresh reproduction steps for 1.46.8:

  1. Get a fresh Windows 10 install, e.g. on VirtualBox (use snapshots!).
  2. Install Delta Chat Setup 1.46.8.
  3. Launch Delta Chat.
  4. Create a Chatmail account. You'll see that database dir is in AppData\Local\DeltaChat
  5. Quit Delta Chat
  6. Install Delta Chat from Microsoft Store.
  7. Launch Delta Chat from Microsoft Store. ℹ Go to View -> Developer -> Open Logs Folder, notice that it's AppData\Local\DeltaChat\logs and not AppData\Local\Packages\merlinux.DeltaChat...\LocalCache\Local\DeltaChat.
  8. 🔁 Repeat the reproduction steps That is, "add account", then "back". Or try to delete an account.

💥 Delta Chat crashes.

Some extra things I did after 10. Uninstall the Setup.exe version of Delta Chat 11. Launch the Microsoft Store version 12. 🔁 Repeat the reproduction steps 💥 Delta Chat still crashes. 13. "Repair" and "Reset" the app in Windows app settings 14. 🔁 Repeat the reproduction steps 💥 Delta Chat still crashes. 15. Uninstall Delta Chat. You now have no Delta Chat instances installed on the system - neither the Store nor the Setup.exe version. 16. Install Delta Chat from Microsoft Store 17. 🔁 Repeat the reproduction steps 💥 Delta Chat still crashes. 18. Uninstall Delta Chat 19. Restart the PC 20. Install Delta Chat from Microsoft Store 21. 🔁 Repeat the reproduction steps 💥 Delta Chat still crashes. 22. Install the Setup.exe version of Delta Chat again and launch it 23. 🔁 Repeat the reproduction steps It works fine (because it's a Setup.exe version).

The only way I managed to NOT reproduce the issue is by installing Delta Chat from Microsoft Store right away, prior to ever installing the Setup.exe version on a particular Windows installation.

  1. Get a fresh Windows 10 install, e.g. on VirtualBox.
  2. Install Delta Chat from Microsoft Store
  3. Launch Delta Chat
  4. Create an account.
    • You'll notice that if you View -> Developer -> Open Log Folder, the path will be AppData\Local\Packages\merlinux.DeltaChat...
    • ⚠️ However, if you go to Help -> About Delta Chat, you'll see that database dir is AppData\Local\DeltaChat\accounts\.... In reality this directory does not exist!
  5. 🔁 Repeat the reproduction steps

✅ Everything works fine!

And then if I additionally install the Setup.exe version and launch it, a new directory will be created, AppData\Local\DeltaChat, and the accounts created in the Microsoft Store version will not appear there: the two instances of Delta Chat will act separately. ✅ No crashes will appear.


In short, I believe that Delta Chat is broken for all Windows users who have had a Setup.exe version prior to switching to the Microsoft Store version.

nicodh commented 4 weeks ago

So I could reproduce this error with the install procedure as described above. The root cause is "failed to remove account data Caused by: The process cannot access the file because it is being used by another process. (os error 32)"

Since BackendRemote.rpc.removeAccount is called async the app waits quite some time for a response, which comes finally as an error and is catched in OnboardingScreen->onClickBackButton. There we only show an alert dialog if the error is of instance Error which is not the case (??). But there is a error.message, so maybe we should at least show that and redirect to the NoAccountSelected screen by calling window.__changeScreen(Screens.NoAccountSelected) after closing the dialog.

That would at least improve the user experience "a bit".

Finally it is only possible to solve the root cause in core. We have to find why there is "another process" using the account data. @link2xt

By the way - after reloading the website by pressing F5 in dev tools or by clicking the reload button on the crash screen everything works as expected and the temporary account is not visible any more (but the account data still exists on disk)

Simon-Laux commented 4 weeks ago

We have to find why there is "another process" using the account data

electron is likely the other process, like it it still holds a file handle to a file from the accounts blob directory like an image.

Also there are tools on windows that you can use to check what programs currently use a file. there is a tool for that in the power toys and you can browse open file handles with process explorer.

winget install --id Microsoft.PowerToys --source winget
WofWca commented 4 weeks ago

Some more debugging.

I tried to use PowerToys. After clicking the "Delete Account" button, PowerToys shows no processes using the to-be-deleted account's folder. The same goes for the files inside., including dc.db.

After the "Delete Account" is pressed, I can delete the account's directory myself using explorer and it doesn't complain that "it's being used by another process" (which is not the case if I try to delete the folder without pressing "Delete Account").

If I delete the directory manually this way while Delta Chat is hung, it doesn't unhang, but instead, after try_many_times finishes, it gives a different error: "failed to remove account data\n\nCaused by:\n The system cannot find the file specified. (os error 2)": I assume it cannot find the account's directory (since I just deleted it).

If I instead delete the contents of the directory while Delta Chat is hung, it doesn't unhang either and, after a minute, the error remains to be the same (failed to remove account data\n\nCaused by:\n The process cannot access the file because it is being used by another process. (os error 32)).