How to replicate IndexedDB "Database deleted by request of the user" error in ios14?

I'm using this js package  https://www.npmjs.com/package/idb%C2%A0to manage a simple indexedDB implementation on a web app.

I'm using the excellent https://www.npmjs.com/package/idb%C2%A0package to manage a simple indexedDB implementation on a web app.

I'm having this error "UnknownError: Database deleted by request of the user" reported to our error reporting system for a significant number of iOS users and I'm having trouble replicating.

It seems to have so far only affect users on:

  • Mobile Safari 14.6, 14.4.2, caught by try/catch
  • Instagram webview, iOS 14.7.1 - not caught be try/catch

I think the source of the error is this line in webkit https://github.com/WebKit/WebKit/blob/e98ff129bc8eba06ac17105f19c5f0e142aab853/Source/WebCore/Modules/indexeddb/shared/IDBError.h#L40

It seems to relate to the server connection closing. Can anyone help me understand what conditions are required to trigger this error so that I can replicate and try to handle in the app?

A simplified version of the implementation:

// ./store.js
import { openDB } from 'idb'

export const upgrade = (db) => {
  if (!db?.createObjectStore) return null
  db.createObjectStore('example_store_name_1')
}

export const set = async (storeName, val, key) => {
  const dbPromise = openDB('example_db_name', 1, { upgrade })
  if (!window.indexedDB) return null
  return (await dbPromise).put(storeName, val, key)
}

export const count = async (storeName) => {
  const dbPromise = openDB('example_db_name', 1, { upgrade })
  if (!window.indexedDB) return null
  return (await dbPromise).count(storeName)
}
// ./index.js
import { set, count } from './store.js'

export const storeEvent = async (storeName, value, key) => {
  try {
    const rowCount = await count(storeName)
    // I process and clear the db in a separate part of the app, this count is just here here as a rough limit to 
    // ensure that I don't keep pushing data into storage if, for some reason, it is not getting cleared elsewhere
    if (rowCount < 500) {
      await set(storeName, value, key)
    }
  } catch (error) {
    // error reported to error monitoring tool
  }
}

Some of the things I have tried to replicate (on Instagram webveiw, iOS 14.7.1 or Mobile Safari 14.6):

  • saving a massive object to idb and closing or backgrounding Instagram or Safari mid transaction
  • saving a massive object to idb across multiple Safari tabs at the same time
  • manually deleting idb db from Safari while transaction is in progress - seems to generate either "UnknownError: * Connection is closing." or "AbortError: The transaction was aborted, so the request cannot be fulfilled." - both caught by try/catch
  • Safari incognito
  • Setting Safari privacy to store no cookies (or any other form of browser storage)
  • this transaction lifetime bug https://github.com/jakearchibald/idb#transaction-lifetime
  • ... Google - nothing for this error other than the webkit source code.

Any suggestions appreciated. I'd like to understand particularly how it is triggered in the iOS webview (Instagram) as these errors are not caught by try/catch currently.

We are having the same problem. It may be related to the application holding the web view going into the background / becoming inactive, but not clear yet.

We've wrapped our indexedDB calls with retries which helps in some cases, but they still more often just retry a few times and eventually fail with the same error. Would be interested to hear if you have made any discoveries or progress.

How to replicate IndexedDB "Database deleted by request of the user" error in ios14?
 
 
Q