dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.7k stars 642 forks source link

Unknown error occurs on iOS PWA (UnknownError / DatabaseClosedError / Need to reopen db) #2008

Open AlexanderMelde opened 5 months ago

AlexanderMelde commented 5 months ago

Hello, In our PWA which is compiled for iOS using Capacitor some users are experiencing the following error:

We assume that this error occurs after the app is in the background for a while (e.g. the user locked the screen or used multitasking), as similar errors occur for other PWAs as well.

In addition to this first error, two Dexie specific errors are thrown:

When researching the reason for the "chrome specific" workaround we found this comment in #543, however in our case its neither chrome (instead it's Mobile Safari UI/WKWebView) nor "clear cookies and site data", just normal app use.

As a result of these errors, our app becomes unstable until properly restarted.

Do you have an idea of how to prevent/resolve or catch these errors?

Console Log image

Thank you for your help and this amazing library!

dfahlander commented 5 months ago

The warning logs from dexie are not thrown errors but console.warning() when dexie need to workaround a situation that can occur on Chrome. In this case we get a similar issue with the underlying Safari engine that cordova runs the webapp on (if I'm correct). According to the logs, Dexie's workarounds does not help in this case as the database continue to complain.

It would be interesting if you could log some number from StorageManager.estimate() on your clients to see whether low storage on the device could be something that could trigger this.

Another theory would be memory pressure on the device: https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/354#issuecomment-486495346. Don't know if there are any way in cordova to log available RAM - that would also be very interesting data to collect.

If you would be able to get more info about storage or memory in when the issue happens, please share!

AlexanderMelde commented 5 months ago

Thank you for your assessment of the situation! As the issue only occurs occasionally, we unfortunately were not able to reproduce it yet and hence could not measure the storage or memory so far. I will send an update once we capture one of these errors with storage and memory estimates.

lincolnthree commented 3 months ago

For us, this has happened to over 1,900 users over 21,000 times. It only occurs when the app has been in the background, then returns to the foreground later. There is an open WebKit bug for this as well:

It was a regression in Safari 17.4+ and it seems like they think they've fixed it for 17.6. All we can do is wait, unfortunately -- but the good news is there may be hope on the horizon.

https://bugs.webkit.org/show_bug.cgi?id=273827

image

In truth, this is the liability of building web-apps as native replacements. Browsers are still a huge source of unreliability and compatibility concerns and Safari is the new Internet Explorer.

Reporting, commenting and voting on bugs, providing trace info, and reproductions is the best course of action I've found.

aeharding commented 3 months ago

Seemingly not resolved in 17.6: https://bugs.webkit.org/show_bug.cgi?id=277615

lincolnthree commented 3 months ago

Ugh.

aeharding commented 1 month ago

Can anyone share a workaround they are using? I am getting regular user reports on my Capacitor app.

louis123562 commented 1 month ago

Can anyone share a workaround they are using? I am getting regular user reports on my Capacitor app.

I would like to know a workaround, too. Our capacitor users report the same problem. All that we can do at least is to show an alert, if the storage couldnt be initialized, read or write.

import { Storage } from '@ionic/storage-angular';

...

try {
      const storage = await this.storage.create();
      this._storage = storage;
    } catch (e) {
      console.error("STORAGE INITIALIZE ERROR");
      console.error(e);
      alert("Storage Initialize Error. Please close the app completly and open again.");
    }

This cannot be a permanent way of handling this...

dfahlander commented 1 month ago

I put a comment on one of the webkit issues this regards to, https://bugs.webkit.org/show_bug.cgi?id=273827, but that one is closed in belief of this having been resolved in iOS 17.6. Alexey Proskuryakov kindly replied directly asking us to file a new bug in their bugzilla where we could refer to this issue.

@louis123562, @AlexanderMelde or @lincolnthree, could anyone of you file the issue on https://bugs.webkit.org ? I will weigh in also! And I know at least one more dexie user having the same issue when running their app on iOS so we could together do our best to give this issue attention!

louis123562 commented 1 month ago

I put a comment on one of the webkit issues this regards to, https://bugs.webkit.org/show_bug.cgi?id=273827, but that one is closed in belief of this having been resolved in iOS 17.6. Alexey Proskuryakov kindly replied directly asking us to file a new bug in their bugzilla where we could refer to this issue.

@louis123562, @AlexanderMelde or @lincolnthree, could anyone of you file the issue on https://bugs.webkit.org ? I will weigh in also! And I know at least one more dexie user having the same issue when running their app on iOS so we could together do our best to give this issue attention!

Hey man, i think there is already an issue on WebKit Bugzilla: https://bugs.webkit.org/show_bug.cgi?id=277615 I found it here: https://github.com/ionic-team/ionic-storage/issues/317