firebase / firebase-js-sdk

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

QuotaExceededError logged in console as unhandled error #5000

Closed jens1101 closed 2 years ago

jens1101 commented 3 years ago

Describe your environment

Test case 1 Test case 2
Operating System version KaiOS 2.5 Ubuntu 20.04
Browser version Hosted app (equal to Firefox 48) Firefox 48
Firebase SDK version 8.6.7 8.6.7
Firebase Product Analytics Analytics

Describe the problem:

When the device's storage is full and I run the isSupported function from the Analytics package then I get a QuotaExceededError logged to my console as an error.

Steps to reproduce:

Case 1
  1. Fill up device's storage so that Firefox's storage quota will be reached
  2. Run firebase.analytics.isSupported()
  3. QuotaExceededError is logged to the console
Case 2
  1. Fill up device's storage so that Firefox's storage quota will be reached
  2. Run indexedDB.open('foo').onerror = function () {}
  3. QuotaExceededError is logged to the console
Case 3
  1. Fill up device's storage so that Firefox's storage quota will be reached
  2. Run indexedDB.open('foo').onerror = function () { return true }
  3. Nothing is logged to the console

Note: It seems that IndexedDB will only consider an error as "handled" if the error handler returns a truthy value.

Relevant Code:

This happens because the below handling function does not return a truthy value:

https://github.com/firebase/firebase-js-sdk/blob/ed4f95ceef98b4ae03864969c37f3232a00b7929/packages/util/src/environment.ts#L172-L174

google-oss-bot commented 3 years ago

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

looptheloop88 commented 3 years ago

Hi @jens1101, thanks for the report. Could you please share the SDK version, browser version and complete error logs that you're getting? Also, please follow the template when filling an issue, moving forward. Thanks!

jens1101 commented 3 years ago

@looptheloop88 I apologise for the missing information. I updated the Issue description with all the information I have. Please let me know if it's sufficient.

looptheloop88 commented 3 years ago

Hi @jens1101, thanks for providing the additional information. I appreciate it. I'm not really sure if this issue affects not only Analytics, but other Firebase products that use IndexedDB as well. Let me check and raise this matter with our engineers here and update this thread once I have any information to share.

hsubox76 commented 3 years ago

I had a hard time filling the quota in order to reproduce your error exactly but I used a Firefox Private Window which also triggers indexedDB's request.onerror and wasn't able to see the error. There's a try/catch in the analytics.isSupported() method that wraps the validateIndexedDBOpenable() from util/environment.ts that you linked above, which is successfully catching the error, for me.

This is consistently logging false for me in the Firefox Private Window, which I've verified does trigger indexedDB's request.onerror.

  const isSupported = await firebase.analytics.isSupported();
  console.log(isSupported);

I have a few questions: 1) How are you using analytics.isSupported() in your code? 2) Can you paste the full text of the error in the console? 3) If you do your experiment with your case 2 and case 3 using a Firefox Private Window instead of by filling the quota, do you get the same results? Wondering if there's something special with the QuotaExceededError specifically.

jens1101 commented 3 years ago

@hsubox76 Thank you for your efforts! Please find below the answers to your questions:

  1. Here is a snippet from our codebase:

    export const initFirebase = async (firebaseConfig) => {
    
     firebase.initializeApp(firebaseConfig);
    
     let isSupported;
    
     try {
       isSupported = await firebase.analytics.isSupported();
    
       if (isSupported) {
         firebase.analytics();
       }
     } catch {
       isSupported = false;
     }
    
     firebase.performance();
    };

    We are using a React app, this initialisation function gets called when our app is bootstrapped. I know that the try-catch block is technically not necessary, but we kept it there for safety.

  2. Here is a screenshot of my Firefox 48 console when I run our project in a regular browser window on a virtual machine with its storage filled up (note that I had to redact some of the logs): Firefox 48 console
  3. When I run my test cases 2 and 3 in a private browser window on a virtual machine with enough storage then here is what I get in the console: image Note that no error is logged to the console when the error handler returns true.

    Additionally, here is a screenshot of my Firefox 48 console when I run our project in the same window (note that I had to redact some of the logs): Firefox private console

Additional Information for Testing

I test this by running a VirtualBox virtual machine with the following configuration:

I then downloaded the Firefox 48 files from here and run the firefox executable. This is what I use for testing.

To fill up the hard drive space I do the following:

  1. Open a terminal
  2. Run fallocate -l 10G large_file.img. This will allocate as much disk space as possible. It will error out, but that's okay. You should now have the large_file.img file in your home direcotry.
  3. Run df to confirm that no free hard drive space is left.
jens1101 commented 3 years ago

@hsubox76 Has there been any update on this? Is there anything else that you need from me?

iamashish121 commented 2 years ago

Hi @jens1101 , Were you able to solve this issue ?

jens1101 commented 2 years ago

@iamashish121 No, unfortunately not. We decided to accept this as a possible error that users might encounter.

hsubox76 commented 2 years ago

I can't currently reproduce this as it difficult to access the OS's in question and the Firefox version is older. I'm not seeing it in the current version of Firefox. Downgrading to Firefox 48, I was unable to get the current versions of the SDK to run, so I am guessing that you have to stick with some version of Firebase v8 in order to use it in this environment. Unfortunately we won't be adding any more updates to the v8 SDK, and any fix we found would be added to v9 going forward.

If anyone's having this issue with the v9 SDK, feel free to update. If it's with an older browser, let me know what you're doing to get v9 to work in the older browser (perhaps I'm missing something obvious).

jens1101 commented 2 years ago

@hsubox76 Thanks for the update. For me this bug only happens on Firebase v8 on Firefox v48, just as you described. Considering that you won't be adding any more updates to Firebase v8 then I think this issue can be closed.