firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.81k stars 884 forks source link

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

Open AugustinGrigorov opened 4 years ago

AugustinGrigorov commented 4 years ago

[REQUIRED] Describe your environment

[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

schmidt-sebastian commented 4 years ago

@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).

AugustinGrigorov commented 4 years ago

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

aidanas commented 4 years ago

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"
veeralpatel commented 4 years ago

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

luisfelipesd commented 4 years ago

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

zeari commented 4 years ago

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

same here :face_with_head_bandage:

aToO57 commented 4 years ago

Same here :(

schmidt-sebastian commented 4 years ago

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.

olearycrew commented 4 years ago

Is anyone aware of a workaround for users?

Aquahugs commented 4 years ago

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

IvanDeluxe commented 4 years ago

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 :(

schmidt-sebastian commented 3 years ago

@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.

b0ot commented 3 years ago

Same issue using Google Chrome on iphone

abarax commented 3 years ago

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

baptisteArno commented 3 years ago

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?

douglasrcjames commented 3 years ago

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?

bozobit commented 3 years ago

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.

douglasrcjames commented 3 years ago

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!

rupert-huelsey-tally commented 3 years ago

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?

aaronmotayne commented 3 years ago

Also happening to me :/

PeterChen1997 commented 3 years ago

Also happening to me :/

rupert-huelsey-tally commented 3 years ago

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.

ajbarry commented 3 years ago

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

prgwar93 commented 3 years ago

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.

cyanerd commented 2 years ago

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?

m-nathani commented 2 years ago

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/

rupert-huelsey-tally commented 2 years ago

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

m-nathani commented 2 years ago

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

Current Firebase version we using:

"firebase": "^9.6.8",.

dodomui commented 2 years ago

The problem still presist with firebase@9.8.1

dconeybe commented 2 years ago

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.

xaphod commented 2 years ago

Hi @dconeybe is there an update? It's been 2 months, and this crash is happening to our users every hour of every day. This is on the latest firebase at the moment, 9.9.0 Hope there is an update soon. If not, please could you ask for more resources to be allocated to your team to fix this

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

dconeybe commented 2 years ago

@xaphod Sadly, no updates. I realize that this issue is frustrating and I wish I had a better response for you. Something that would be incredibly helpful would be a reproducible scenario, especially with a minimal app that we could clone and reproduce for ourselves. If you have the ability to reproduce this crash then please share those details. Even if you are unable to share your code, if you can reproduce the crash then we could ask you to try some different things and/or capture more detailed information. It appears that the crash is related to Safari going into the background, which may cause Firestore to lose its disk access.

DavidWeiss2 commented 2 years ago

You can reproduce this bug in IOS by removing your cookies.

As little as I can understand, the cause for this bug is when the user/os blocks the site permission to disk.

For example by removing the cookie that is responsible for storage.

I can suggest storing the response in memory and asking again for permission.

gh123man commented 2 years ago

Also hitting this bug on 9.9.1 - using the vanilla AuthUI as described in the docs. As others have mentioned (and in other threads) to repro in chrome:

  1. open page (being signed out)
  2. F12 -> Application -> Strorage -> clear site data
  3. start auth flow - will get this error.
bgbruno commented 1 year ago

for me it is not "firebase related" https://bugs.chromium.org/p/chromium/issues/detail?id=1085724#c14

derrickrc commented 1 year ago

Also seeing this error in our error reporting - it seems to mostly (but not exclusively) affect our users who are not based in North America (Middle East, APAC, etc.).

Browser is WebKit 605.1.15 (mobile Safari) 8.6.8/firebase-app.js 7.17.2/firebase-auth.js 8.6.8/firebase-database.js