Bug 277615 - IndexedDB failing with "UnknownError: Connection to Indexed Database server lost."
Summary: IndexedDB failing with "UnknownError: Connection to Indexed Database server l...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Website Storage (show other bugs)
Version: Safari 17
Hardware: iPhone / iPad Unspecified
: P2 Critical
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-08-04 14:29 PDT by Nisala
Modified: 2024-08-27 02:09 PDT (History)
6 users (show)

See Also:


Attachments
Example of exception in Sentry, showing iOS 17.6 (392.88 KB, image/png)
2024-08-04 14:29 PDT, Nisala
no flags Details
zarko - example exception log (143.90 KB, image/png)
2024-08-27 01:59 PDT, Zarko
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nisala 2024-08-04 14:29:24 PDT
Created attachment 472056 [details]
Example of exception in Sentry, showing iOS 17.6

My Capacitor (WebView in iOS app framework) app's connection to IndexedDB will spontaneously close and fail to reopen, throwing this error: "UnknownError: Connection to Indexed Database server lost. Refresh the page to try again".

Although this bug was closed last month saying it was fixed in iOS 17.6 (https://bugs.webkit.org/show_bug.cgi?id=273827), I am still getting Sentry reports for iOS 17.6 with this error. I've attached a screenshot of the exception from Sentry, and am happy to provide any more information that I can. Based on my Sentry reports, the bug still seems to happen when the user uses the app, puts it into the background for a few hours, and then brings it back to the foreground to use it again. This is a critical bug -- it can't be fixed without the user force-closing and relaunching the app, and as a result, I'm losing users (as I'm sure are many others).
Comment 1 Radar WebKit Bug Importer 2024-08-05 09:06:12 PDT
<rdar://problem/133219094>
Comment 2 Ahmad Saleem 2024-08-05 09:07:55 PDT
@Nisala - is it possible to attach small reproduction in order to help us understand the problem. All relevant engineers are in CC.
Comment 3 Nisala 2024-08-08 00:13:06 PDT
I'll try my best to create a reproduction, but I still don't have a good way to reproduce the error consistently. It seems very much up to the whims of iOS. I was hoping that y'all would have a reproduction already from the earlier bug reports of this issue.

From what I've seen on Sentry, the bug happens when an app that uses IndexedDB via a Webview (app.getbaseline.baseline, in my case) is put into the background and then re-opened many hours later. When the app is reopened, the database is closed and can't be reopened, and throws the UnknownError.
Comment 4 alex 2024-08-11 08:07:36 PDT
I can confirm this issue as well (user reports, and firsthand) on iOS 17.6.

It is seemingly sporadic and I'm unable to reproduce on demand.
Comment 5 Zarko 2024-08-27 01:59:51 PDT
Created attachment 472314 [details]
zarko - example exception log

See attached example exception log.
It seems like it might also have to with an event where there is no internet connection when the app comes back to foreground.

The exception is close to impossible to reproduce myself. For the time being it's clogging our error reporting system (blowing up our quota) and it's not clear what kind of runtime effect it has for users.

Given that the error message says "Connection to Indexed Database server lost. Refresh the page to try again", is it even worth trying to reload the (web) app? Would that recover the IndexedDB database/connection?
Comment 6 Zarko 2024-08-27 02:09:00 PDT
If it may help, I can inform that we're using https://www.npmjs.com/package/idb-keyval, which works well until things go south with the IndexedDb and read/write operations starts to fail silently. I made an attempt there with a pull request ("Try to reopen database in case of unexpected closure" - https://github.com/jakearchibald/idb-keyval/pull/175) but the library project doesn't seem to well maintained...

I believe Dexie.js and Firebase have similar recovery logic in place, though it is probably only a partial solution - not enough if the db cannot be re-opened at all within the session.