firebase / firebase-js-sdk

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

experimentalTabSynchronization broken in 5.7.0 (Failed to obtain primary lease for action 'Collect garbage') #1436

Closed varung closed 5 years ago

varung commented 5 years ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

I had a react project that used firebase and worked well for several months. I then updated the code to the newest firebase sdk and to use multi-tab persistence. For the first time I saw the following console errors. (It's possible these occurred earlier and I did not notice, but I know for sure I did not get errors before October 2018. The app had been developed several months before October and ran well without problems.)

Steps to reproduce:

It seems to happen when multiple tabs are used, and multi-tab persistence is enabled. When it happens, it happens many times. (sometimes 100s).

index.cjs.js:151 Uncaught Error: FIRESTORE (5.5.9) INTERNAL ASSERTION FAILED: AsyncQueue is already failed: FirebaseError: The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab. at new t (index.cjs.js:346) at index.cjs.js:11746 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) at e.r.nextCallback (index.cjs.js:8225) at index.cjs.js:8195 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) at u (index.cjs.js:151) at e.verifyNotFailed (index.cjs.js:7763) at e.enqueue (index.cjs.js:7715) at e.enqueueAndForget (index.cjs.js:7707) at e.handleDelayElapsed (index.cjs.js:7669) at index.cjs.js:7645 at Worker.worker.onmessage (HackTimer.js:134) u @ index.cjs.js:151 e.verifyNotFailed @ index.cjs.js:7763 e.enqueue @ index.cjs.js:7715 e.enqueueAndForget @ index.cjs.js:7707 e.handleDelayElapsed @ index.cjs.js:7669 (anonymous) @ index.cjs.js:7645 worker.onmessage @ HackTimer.js:134

Relevant Code:

// Code that sets up firebase

import firebase from 'firebase'

firebase.initializeApp(config) export default firebase; export const provider = new firebase.auth.GoogleAuthProvider(); export const auth = firebase.auth();

export let db = firebase.firestore(); const settings = {/ your settings... / timestampsInSnapshots: true}; db.settings(settings);

db.enablePersistence({experimentalTabSynchronization:true}).then(() => { console.log("Woohoo! Multi-Tab Persistence!"); }) .catch(function(err) { console.log("failed to enable persistence:" + err.code) });

// as an example, this is the method of a react object that uses firebase // example is handling when the user leaves a form element with onBlur handleChangeAndSave = (e) => {
const t = e.target; const value = (t.type === 'checkbox')?t.checked:t.value;
this.fbref().set({ [t.name]: value, _updated : new Date() }, {merge: true})
}

google-oss-bot commented 5 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

mikelehen commented 5 years ago

Thanks for the report! This is very possibly a bug in the experimental multi-tab synchronization support.

In order to track this down, we will likely need a way to reproduce the problem so that we can debug what is going wrong. Failing that, it would be helpful if you can see if there is an earlier error being logged. The error you've reported suggests that the "The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab." error happened earlier, and hopefully it was logged with a more accurate callstack, that could help us track this down. Thanks!

varung commented 5 years ago

index.esm.js:77 [2018-12-21T10:18:05.142Z] @firebase/firestore: Firestore (5.5.9): Failed to obtain primary lease for action 'Collect garbage'. s @ index.esm.js:77 index.esm.js:77 [2018-12-21T10:18:05.142Z] @firebase/firestore: Firestore (5.5.9): INTERNAL UNHANDLED ERROR: FirebaseError: The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab. at new t (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:738041) at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:874855 at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833120 at e.wrapUserFunction (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832962) at e.wrapSuccess (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833085) at e.nextCallback (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832730) at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832285 at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833120 at e.wrapUserFunction (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832962) at e.wrapSuccess (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833085) s @ index.esm.js:77 index.cjs.js:346 Uncaught (in promise) Error: The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab. at new t (index.cjs.js:346) at index.cjs.js:11768 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) at e.nextCallback (index.cjs.js:8225) at index.cjs.js:8195 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) 21:1 Uncaught (in promise) Error: The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab. at new t (index.cjs.js:346) at index.cjs.js:11768 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) at e.nextCallback (index.cjs.js:8225) at index.cjs.js:8195 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) index.cjs.js:7729 Uncaught Error: The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab. at new t (index.cjs.js:346) at index.cjs.js:11768 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) at e.nextCallback (index.cjs.js:8225) at index.cjs.js:8195 at index.cjs.js:8255 at e.wrapUserFunction (index.cjs.js:8241) at e.wrapSuccess (index.cjs.js:8255) index.esm.js:77 [2018-12-21T10:18:05.205Z] @firebase/firestore: Firestore (5.5.9): FIRESTORE (5.5.9) INTERNAL ASSERTION FAILED: AsyncQueue is already failed: FirebaseError: The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab. at new t (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:738041) at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:874855 at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833120 at e.wrapUserFunction (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832962) at e.wrapSuccess (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833085) at e.nextCallback (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832730) at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832285 at https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833120 at e.wrapUserFunction (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:832962) at e.wrapSuccess (https://firepomo.firebaseapp.com/static/js/main.d51247b3.js:1:833085)

varung commented 5 years ago

Not sure if the above helps.

mikelehen commented 5 years ago

@varung Thanks! That definitely helps. I believe I know what the cause is and we'll work on getting a fix into an upcoming release.

In the meantime I believe you could avoid the issue by disabling garbage collection with:

firebase.firestore().settings({
  ...
  cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED
});
mikelehen commented 5 years ago

This should be fixed in the 5.7.2 release that went out last week. Thanks!