firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

[Error] InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.

Open AugustinGrigorov opened this issue 4 years ago • 34 comments

[REQUIRED] Describe your environment

  • Operating System version: iOS Version:13.3.1
  • Browser version: Mobile Safari Version:13.0.5
  • Firebase SDK version: 7.9.1
  • Firebase Product: firestore

[REQUIRED] Describe the problem

Steps to reproduce:

I can't reliably reproduce it so not entirely sure what specifically causes it but here is the Sentry error: https://sentry.io/share/issue/03f7cacb9f394cdd9867f13ad40345d8/ Once this errors subsequent requests start failing like this: https://sentry.io/share/issue/aab1ab9ce88e4d50a3e40edbc27c0700/

Relevant Code:

This is my firebase setup: https://github.com/AugustinGrigorov/vocabulary-builder/blob/master/src/utils/firebase.js

AugustinGrigorov avatar Mar 04 '20 12:03 AugustinGrigorov

@AugustinGrigorov Sorry to hear about your troubles!

It looks like you are experiencing something akin to https://github.com/firebase/firebase-js-sdk/issues/1533. The good news is that you are not on your own, the bad news is that this seems to be a longstanding issue that is caused by unexpected behavior in Mobile Safari that we haven't been able to completely work around.

We are currently discussing how to make our SDK more tolerant to IndexedDb failures, which would address this issue, as well as #1533 and #2581. We already retry IndexedDb writes up to five times, but this doesn't seem to help in some scenarios (e.g. when the app is not in the foreground).

schmidt-sebastian avatar Mar 05 '20 03:03 schmidt-sebastian

Thanks! That makes sense. Cross-browser issues can be annoying.

AugustinGrigorov avatar Mar 06 '20 10:03 AugustinGrigorov

We are also experiencing similar issue. On lates version - 7.17.1 Unfortunately, I was not able to recreate it on an isolated hello world but it happens frequently on our production app with following steps/setup. We use persistence enabled Firestore. Our app is Cordova based multi page app. Between navigations we call firebase destroy and only then change the href. Firebase is then reinitialised on a next screen app on the next screen. The problem happens when users navigate around a bit, usually about 3 screen. Then put app to background. Disable and re-enable wifi. Then bring app to foreground. At that point we get errors in logs:

  @firebase/firestore: – "Firestore (7.17.1): INTERNAL UNHANDLED ERROR: " (1)
Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
Unhandled Promise Rejection: InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
 @firebase/firestore: – "Firestore (7.17.1): FIRESTORE (7.17.1) INTERNAL ASSERTION FAILED: Unexpected state"

aidanas avatar Jul 27 '20 17:07 aidanas

+1 -- seems to be happening most on Mobile Safari

veeralpatel avatar Aug 20 '20 02:08 veeralpatel

this is affecting all of our users for the registering process. any update?

luisfelipesd avatar Aug 23 '20 21:08 luisfelipesd

this is affecting all of our users for the registering process. any update?

same here :face_with_head_bandage:

zeari avatar Aug 27 '20 15:08 zeari

Same here :(

aToO57 avatar Aug 27 '20 22:08 aToO57

Can one of you provide the logs that immediately proceed these failures? This will help me narrow down what transaction is failing. Furthermore, do you see more or fewer of these errors since 7.18? 7.18 is the first version that is meant to address these issues.

FYI Iam on vacation next week but will pick up this work once I get back.

schmidt-sebastian avatar Aug 28 '20 18:08 schmidt-sebastian

Is anyone aware of a workaround for users?

olearycrew avatar Aug 28 '20 19:08 olearycrew

Yep still having this problem as well :( really effecting user growth for a project im currently launching

Aquahugs avatar Aug 29 '20 18:08 Aquahugs

Unfortunately, I have no logs to share, but we have a stocktaking app in which you count items in stock by adding them to the current count. This means that during a single inventory count user repeatedly adds items to count.

There's a user that's on iOS 13.16.1 (Firebase version 7.19 currently) and she usually has to reload the app after adding 10 or 20 items (that's 10 or 20 writes) because she experiences true data loss.

We've set a .catch((e)=>{...}) that disables the button in question if something goes wrong, but in this case nothing happens - she probably gets an error in the console, but that is currently beyond our powers :)

I've tested the "catch" by ~~calling firebase.firestore().terminate()~~ disabling persistence + setting Network to Offline and it works as expected, but in her case, she can continue using the app, there's just no data being added / removed :(

IvanDeluxe avatar Sep 02 '20 11:09 IvanDeluxe

@IvanDeluxe For operations that are initiated by the user, we reject the operation itself if there is in IndexedDB error. This means that any operations that returns a Promise or a onSnapshot callback can fail with an IndexedDB error, but unlike before this should not crash the client. You should be able to retry these operations, but we suggest that you only do so when the database connection is available again (likely when the app is in the foreground). It would be interesting to see if this behavior works for you, since this code is fairly new to our SDK.

We have decided to only automatically retry operations in the SDK if they are not driven by user interactions (e.g. network calls), as we provide certain ordering guarantees for user-driven operations that would essentially mean that our SDK would need to stall as we poll for IndexedDB access.

schmidt-sebastian avatar Sep 09 '20 15:09 schmidt-sebastian

Same issue using Google Chrome on iphone

b0ot avatar Nov 07 '20 11:11 b0ot

I am having the same issue using PouchDB on iOS safari webkit.

abarax avatar Nov 13 '20 04:11 abarax

Same issue (Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36). What does this error mean for the end user?

baptisteArno avatar Nov 17 '20 08:11 baptisteArno

Experiencing this with my app launching with a small percentage of users register for an email account. Users reporting seems to be coming from iPhone Safari. Not able to reproduce on my end. Their account details are not being pushed to the Firestore users collection so a fix, for now, seems to be just deleting their Firebase Auth user data, and telling them to try to create an account again.

Any idea for a fix on this?

douglasrcjames avatar Feb 14 '21 20:02 douglasrcjames

Experiencing this with my app launching with a small percentage of users register for an email account. Users reporting seems to be coming from iPhone Safari. Not able to reproduce on my end. Their account details are not being pushed to the Firestore users collection so a fix, for now, seems to be just deleting their Firebase Auth user data, and telling them to try to create an account again.

Any idea for a fix on this?

Exactly what is happening to me.

bozobit avatar Feb 14 '21 21:02 bozobit

I just applied a hotfix for my app by updating firebase to v8.1.2 based on this thread: #1926 , hopefully the error what happen anymore!

douglasrcjames avatar Feb 14 '21 21:02 douglasrcjames

Ok, so I did just find a very interesting thing which might explain what is going on: I had a friendly who ran into this issue. I asked him to send me his IP via whatsmyip.net and he sent me back a screen shot that only had an IP v6 in it. Asked him to switch to wireless which had both IP v4 and IP v6 and it worked. I am getting the suspicion that - if the client doesn't have an IP v4, Firebase and iOS don't play well. Any thoughts on that?

rupert-huelsey-tally avatar Feb 27 '21 01:02 rupert-huelsey-tally

Also happening to me :/

aaronmotayne avatar Apr 05 '21 01:04 aaronmotayne

Also happening to me :/

PeterChen1997 avatar Apr 08 '21 11:04 PeterChen1997

Ok, so we got this from about 5-10% of our users experiencing this in some way or another to zero. The fix that worked for us is to update the libraries to an 8.x release (see release notes). Apparently quite a bit of work has been put into resolving this issue and it has been successful.

rupert-huelsey-tally avatar Apr 08 '21 13:04 rupert-huelsey-tally

Noice! Thanks so much for the confirmation @rupert-huelsey-tally.

ajbarry avatar Apr 08 '21 19:04 ajbarry

We are still facing the issue. I have included the sentry link for reference https://sentry.io/share/issue/cf261ef143ac4c71bb18dd1915a24720/

This issue particularly happens in Iphone.

prgwar93 avatar Aug 27 '21 16:08 prgwar93

We are still facing the issue. I have included the sentry link for reference https://sentry.io/share/issue/cf261ef143ac4c71bb18dd1915a24720/

This issue particularly happens in Iphone.

hello! did u fix this issue?

cyanerd avatar Apr 11 '22 04:04 cyanerd

browser: [Chrome 100.0.4896] os: [Windows 10]

Error: FirebaseError Firebase: Error thrown when writing to storage. Original error: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.. (app/storage-set).

Got this error on windows in chrome.. not really sure how to reproduce or it fix ?

Does anyone know the cause and solution ?

Here is the details of the above error:

https://sentry.io/share/issue/a3d62523030a4b459b3e74e70336e5ea/

m-nathani avatar Apr 14 '22 07:04 m-nathani

@cyanerd and @m-nathani - what is the version of the firebase libraries you are using?

rupert-huelsey-tally avatar Apr 14 '22 12:04 rupert-huelsey-tally

@cyanerd and @m-nathani - what is the version of the firebase libraries you are using?

Current Firebase version we using:

"firebase": "^9.6.8",.

m-nathani avatar Apr 14 '22 13:04 m-nathani

The problem still presist with [email protected]

dodomui avatar May 13 '22 06:05 dodomui

Unfortunately, the Firestore team still does not have a fix for this issue. We are also heads down in other work that prevents us from investigating in a fix. This issue is, however, being tracked on our backlog. Someone from the Firestore team will update this issue if/when we have anything to update. I realize this problem is really causing frustration and I'm sorry that we don't have any better news at this point.

dconeybe avatar May 17 '22 20:05 dconeybe