Skip to content

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

Closed

Description

@dweissjcs

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

Activity

  1. dweissjcs commented on Jan 3, 2024

    @dweissjcs
    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",

  2. dweissjcs commented on Jan 19, 2024

    @dweissjcs
    Author

    bump

  3. lahirumaramba commented on Mar 5, 2024

    @lahirumaramba
    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?

  4. dweissjcs commented on Mar 6, 2024

    @dweissjcs
    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});
     }
    
  5. lahirumaramba commented on Mar 7, 2024

    @lahirumaramba
    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);
    
  6. dweissjcs commented on Mar 8, 2024

    @dweissjcs
    Author

    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

  7. lahirumaramba commented on Mar 11, 2024

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

  8. marcel-happyfloat commented on Apr 28, 2024

    @marcel-happyfloat

    When will sendAll stop working?

  9. LebonNic commented on May 14, 2024

    @LebonNic

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

  10. jandryml commented on Aug 22, 2024

    @jandryml

    any progress on this?

  11. dpereiraegoi commented on Sep 19, 2024

    @dpereiraegoi

    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.

  12. jonathanedey commented on Sep 19, 2024

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions