Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix Firestore SDK hitting "An internal error was encountered in the Indexed Database server" error on iOS?

My Firestore web app sometimes hits the following error on iOS:

@firebase/firestore: Firestore (5.5.0): INTERNAL UNHANDLED ERROR: An internal error was encountered in the Indexed Database server

What is causing this and how do I fix it?

like image 904
Michael Lehenbauer Avatar asked Jan 27 '23 05:01

Michael Lehenbauer


1 Answers

This is due to a bug in iOS versions >= 12.2 and < 13. See https://bugs.webkit.org/show_bug.cgi?id=197050 for details. The bug can occur when the page or app returns to the foreground after being in the background for some period of time. When the error occurs, IndexedDB is left in an unusable state, causing the Firestore SDK to generate the mentioned error and become unusable as well.

The only way to avoid the error is disabling persistence. If you require persistence to be enabled, the only way to potentially recover is to catch the error with a global window.onerror handler and e.g. refresh the page:

window.onerror = function(error) {
  if (error.indexOf("An internal error was encountered in the Indexed Database server") >= 0) {
    // Refresh the page to restore IndexedDb to a working state.
    window.location.reload();
  }
};

More context: https://github.com/firebase/firebase-js-sdk/issues/1670

like image 180
Michael Lehenbauer Avatar answered Feb 09 '23 01:02

Michael Lehenbauer