Skip to content

Upgrade from 11.11.1 to 12.0.0 and change from sendAll to sendEach throwing errors #2418

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

Closed
dweissjcs opened this issue Jan 3, 2024 · 12 comments

Comments

@dweissjcs
Copy link

dweissjcs commented Jan 3, 2024

Hello,
I've upgraded to latest version of firebase-admin and got some deprecation method messages. One of them was sendAll which is gonna be replaced with sendEach. I checked interfaces and description provided in firebase-admin and it look same. But after switching to new sendEach method I started to get errors like

Rejected unknown error: {\"code\":\"app/invalid-credential\",\"message\":\"Failed to determine project ID: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"}

  • Firebase SDK version: 12.0.0
  • Firebase Product: messaging
  • Node.js version: 20.10.0
  • NPM version: 10.2.5

What has changed? Is there different approach to authorisation or something else needed to be changed? Is there any migration guide for upgrade from v11 to v12?

Thank you

@dweissjcs
Copy link
Author

Also while debugging I have noticed circular dependency at
firebase-admin have dependency "@firebase/database-compat": "^1.0.2",
and database-compat have dependency back to "firebase-admin": "11.6.0",

@dweissjcs
Copy link
Author

bump

@lahirumaramba
Copy link
Member

There were no changes to the credentials handling in v12. How do you initialize the SDK? Are you able to share some code samples with us?

@dweissjcs
Copy link
Author

It's not with switch to v12, that upgrade gave us only deprecation message on fcm.messaging.sendAll.. The problem is when we switch from fcm.messaging.sendAll to fcm.messaging.sendEach

Cleaned a lot.. but its visible from it hopefully - "working way"

import fcm, { messaging as fcmTypes, FirebaseError } from 'firebase-admin';

public async sendBulk(items: any[]): Promise<any> {
    const fcmApp = fcm.apps?.find((app) => app?.name === credentials.credentialsId) ?? // this we have in config
      fcm.initializeApp(
        {
          credential: fcm.credential.cert(credentials),
        },
        credentials.credentialsId);
          
    fcm
          .messaging(fcmApp)
          // eslint-disable-next-line deprecation/deprecation -- this is deprecated method, we need to switch to .sendEach
          .sendAll(items)
          .then(({ responses }) => { // do some logic })
          .catch((error) => { // do some logic});
 }

and when we switch to .sendEach, we start getting that mentioned error

import fcm, { messaging as fcmTypes, FirebaseError } from 'firebase-admin';

public async sendBulk(items: any[]): Promise<any> {
    const fcmApp = fcm.apps?.find((app) => app?.name === credentials.credentialsId) ?? // this we have in config
      fcm.initializeApp(
        {
          credential: fcm.credential.cert(credentials),
        },
        credentials.credentialsId);
          
    fcm
          .messaging(fcmApp)
          .sendEach(items)
          .then(({ responses }) => { // do some logic })
          .catch((error) => { // do some logic});
 }

@lahirumaramba
Copy link
Member

Interesting... can you try adding projectId to see if that solves the issue?

initializeApp(
        {
          credential: fcm.credential.cert(credentials),
          projectId: `xxx-xxxxxx-xxx`, // this line
        },
        credentials.credentialsId);

@dweissjcs
Copy link
Author

dweissjcs commented Mar 8, 2024

Thank you this helped.. Before it did not help because we had bad setup of tests which I fixed with this.. Thank you.. Anyway, is there any reason why sendEach is calling RPC one by one? Instead of sendAll where it sent all at once? Its 2-2.5 times slower than sendAll :( Thank you

@lahirumaramba
Copy link
Member

The backend API that was used by sendAll has been deprecated so we had to re implement the functionality using the send API, which sends multiple requests to the backend. We are aware of the performance issues and looking for ways to further optimize the functionality. Stay tuned!

(@jonathanedey FIY)

@marcel-happyfloat
Copy link

When will sendAll stop working?

@LebonNic
Copy link

I think it will stop working on June 20, 2024: https://firebase.google.com/support/faq/#fcm-depr-features

@jandryml
Copy link

any progress on this?

@dpereiraegoi
Copy link

Hi!
Any progress on this?
After migrate to sendEach i have been noticed with my IT team that change decrease the performance but also considerably increases the cost of the server, we need to use many more threads to achieve the same performance.

@jonathanedey
Copy link
Contributor

Hey @dpereiraegoi,
With v12.3.0, sendEach() and sendEachForMulitcast() now use a HTTP/2 connection by default when sending messages. This should provide some performance improvements.

With the deprecation of the batch FCM backend endpoints, each message requires a request to be sent to the backend which explains the increase in threads. This is a limitation of not having a batch endpoint and is beyond the scope of this SDK which is essentially a wrapper for the REST API.

If you continue to experience considerably decreased performance after upgrading to HTTP/2, I'd recommend filing a Firebase support ticket from https://firebase.google.com/support/troubleshooter/contact to share your feedback to reach the correct internal teams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants