Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Uncaught (in promise): cancelled at Refresher.stop() #7805

Closed
bpetrov98 opened this issue Nov 23, 2023 · 17 comments
Closed

Error: Uncaught (in promise): cancelled at Refresher.stop() #7805

bpetrov98 opened this issue Nov 23, 2023 · 17 comments

Comments

@bpetrov98
Copy link

bpetrov98 commented Nov 23, 2023

Operating System

Windows 11

Browser Version

Chrome Version 119.0.6045.160 (Official Build) (64-bit)

Firebase SDK Version

9.17.2

Firebase SDK Product:

AppCheck

Describe your project's tooling

Angular 15.0.0

Describe the problem

Sometimes we get an uncaught promise error, which we can't find a way to catch and we get an email every time it happens on an user device. I also encountered this error in production, but it seems that the application works fine the whole time. If I don't refresh the page, the uncaught promise error won't stop showing and it spams our emails, because we send an email every time there is an error in our application.

Steps and code to reproduce issue

We actually don't know how to reproduce this issue, because it happens randomly, so any suggestions or fixes will be appreciated.
Here is the code for our Firebase Service:

@Injectable({ providedIn: 'root' })
export class FirebaseBrowser {
  public db!: Firestore;
  public storage!: FirebaseStorage;

  constructor() {
    if (typeof window === 'undefined') return;

    let app;
    try {
      app = initializeApp(environment.firebaseConfig);
      this.db = getFirestore(app);
      this.storage = getStorage(app);
    } catch (error) {
      console.error(error);
      throw new Error("Could't initialize firebase App");
    }

    if (!app || !this.db || !this.storage) throw new Error('Firebase initialize app');

    if (environment.ANGULAR_APP_APP_CHECK_DEBUG_TOKEN && environment.ANGULAR_APP_APP_CHECK_DEBUG_TOKEN.length) {
      self.FIREBASE_APPCHECK_DEBUG_TOKEN = environment.ANGULAR_APP_APP_CHECK_DEBUG_TOKEN;
      // this.connectToEmulators(this.store);
    }

    try {
      initializeAppCheck(app, {
        provider: new ReCaptchaV3Provider(environment.recaptcha.siteKey),
        isTokenAutoRefreshEnabled: true
      });
    } catch (error) {
      console.error(error)
    }
  }

  // ** FIRESTORE **
  public firestoreSubscription = (collection: string, documentId: string, callback: (snapshot: any) => void) => {
    try {
      return onSnapshot(doc(this.db, 'configurations', environment.lang, collection, documentId), callback, (error) => {
        console.error('Firebase Subscription Error', error);
      });
    } catch (error) {
      console.error(error);
      throw new Error('Firebase Subscription Error');
    }
  }
}
@bpetrov98 bpetrov98 added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Nov 23, 2023
@google-oss-bot
Copy link
Contributor

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

@jbalidiong jbalidiong added needs-attention api: appcheck and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Nov 23, 2023
@DellaBitta
Copy link
Contributor

Hi @bpetrov98,

Do you have any details on the error at all (stack trace, etc) so that we can narrow down where the issue might be? Thanks!

@bpetrov98
Copy link
Author

Hi @DellaBitta,

I can provide you with the error stack trace in production, where I've replaced our domain with example.com.
Here is the error stack trace:

Error: Uncaught (in promise): cancelled at z (https://example.com/polyfills.cbf2e8875948a0c9.js:1:15977) at https://example.com/polyfills.cbf2e8875948a0c9.js:1:15067 at Kn.reject (https://example.com/polyfills.cbf2e8875948a0c9.js:1:15173) at Hn.stop (https://example.com/390.a68c9bab1fcf9cc9.js:1:7984) at https://example.com/390.a68c9bab1fcf9cc9.js:1:8106 at Generator.next (<anonymous>) at a (https://example.com/main.e261a3b519e48e56.js:1:394275) at j (https://example.com/main.e261a3b519e48e56.js:1:394477) at https://example.com/main.e261a3b519e48e56.js:1:394536 at new e (https://example.com/polyfills.cbf2e8875948a0c9.js:1:18365)

@DellaBitta
Copy link
Contributor

Hi @bpetrov98,

Do you happen to have an unobfuscated stack trace that points to the error within Firebase? I think we found a potential scenario that might cause this error but it would be helpful to know for sure.

Additionally, given our investigation it's our assumption that this error doesn't actually cause any negative behavior (other than spamming you with emails) but it would be helpful if you could confirm that. Do you know if your app continues to operate as expected after the error?

Thanks!

@bpetrov98
Copy link
Author

Hi again @DellaBitta,

We actually don't have any other stack trace, other than the one provided above. Thankfully, this error doesn't actually cause any negative behaviour. We just want to understand why and how it happens and try to prevent it in the future. We've used many catch blocks to try and catch the error, but unfortunately we couldn't catch it.

@DellaBitta
Copy link
Contributor

Ok, I'll see if we can attempt to sort this out internally to the SDK.

@DellaBitta DellaBitta self-assigned this Nov 28, 2023
DellaBitta added a commit that referenced this issue Nov 29, 2023
Install catch handlers for promises in the Derferred object used by in AppCheck. There were some cases where the promise was cancelled and this bubbled up error messages to our clients' applications despite this being expected behavior.

This change is to alleviate the logging reported in issue #7805.
@DellaBitta
Copy link
Contributor

Hi @bpetrov98,

We've identified that the cancelled promise is part of standard App Check SDK behavior, but I just merged a PR that should suppress the propagation of an error message to the console logs. The change will be in our next release. I'll update this issue when it's available. Thanks for the report!

@bpetrov98
Copy link
Author

Thank you for your assistance and quick response, @DellaBitta :)

@DellaBitta
Copy link
Contributor

Hi @bpetrov98,

Firebase JS SDK v10.7.1 has been released. Can you test it out and let us know if there's still an issue? Thanks!

@bpetrov98
Copy link
Author

Hi, @DellaBitta,

We just updated to the latest version yesterday and unfortunately this morning we got the same error in our email inbox.

@DellaBitta
Copy link
Contributor

Hi @bpetrov98,

That's unfortunate. The good news is that this is expected behavior, and it shouldn't cause any adverse effects on the app itself. Have you found that not to be the case at all?

Is the stack trace exactly the same or is the promise not being caught in another location. Also do you have any information about what the app is doing when this stack trace appears? Is the behavior easily reproducible by you, or is it only an issue for a particular customer? Thanks!

@bpetrov98
Copy link
Author

bpetrov98 commented Dec 10, 2023

We can't really reproduce the issue. The stack trace is exactly the same and sometimes randomly while sitting on a page it starts happening. It's just random, but I'm somehow sure that it comes from the Proactive Refresh of App Check. I know that it's expected behaviour, but I find it wrong to get errors like this.

@DellaBitta
Copy link
Contributor

Hi @bpetrov98,

I just wanted to confirm that the user encountering the problem has been using the latest and greatest version of the Firebase SDK (10.7.1) and it's not a PWA that required a rollout for the update to take effect.

I ask because our previous attempt at fixing this problem should have prevented this issue from being encountered again, but that's based on our limited knowledge about what is actually going wrong.

We recently reviewed this issue again with the whole engineering team. I'm sorry to say that we've unsure what else could be triggering this exception given the information that has been provided.

If you can provide any more information about how to reproduce this issue then we'd definitely look into this further, but unfortunately, as of now we're not certain what's causing it, and why the attempted fix didn't work.

@google-oss-bot
Copy link
Contributor

Hey @bpetrov98. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@bpetrov98 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@bpetrov98
Copy link
Author

Hi, @DellaBitta,
I just wanted to say that we no more experience this issue. What we did was update to the version v10.7.1. At first, we've experienced the error a couple of time and suddenly it stopped throwing the error. So, it's been a couple of weeks without receiving emails about the uncaught promise error. We can safely say that this issue is resolved! Thank you and the team for helping me out :)

@DellaBitta
Copy link
Contributor

Hi @bpetrov98, that's great news! Thank you very much for circling back with us!

@firebase firebase locked and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.