Bug 277615

Summary: IndexedDB failing with "UnknownError: Connection to Indexed Database server lost."
Product: WebKit Reporter: Nisala <nisala>
Component: Website StorageAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Critical CC: ahmad.saleem792, alex, ap, sihui_liu, webkit-bug-importer, zarko
Priority: P2 Keywords: InRadar
Version: Safari 17   
Hardware: iPhone / iPad   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=273827
Attachments:
Description Flags
Example of exception in Sentry, showing iOS 17.6
none
zarko - example exception log none

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.