3

I've been getting internal error quite a lot this week while sending messages to my iOS devices through the Node.js library (code is the same, same library version etc.)

It's hard to debug because sometimes it works. When I put a for loop to send 10 messages, my devices would get 3-4.

FirebaseMessagingError: Internal error encountered.
>      at FirebaseMessagingError.FirebaseError [as constructor] (/node_modules/firebase-admin/lib/utils/error.js:42:28)
>      at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/node_modules/firebase-admin/lib/utils/error.js:88:28)
>      at new FirebaseMessagingError (/node_modules/firebase-admin/lib/utils/error.js:254:16)
>      at Function.FirebaseMessagingError.fromServerError (/node_modules/firebase-admin/lib/utils/error.js:287:16)
>      at Object.createFirebaseError (/node_modules/firebase-admin/lib/messaging/messaging-errors.js:34:47)
>      at FirebaseMessagingRequestHandler.buildSendResponse (/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:119:47)
>      at /node_modules/firebase-admin/lib/messaging/messaging-api-request.js:94:30
>      at Array.map (<anonymous>)
>      at /node_modules/firebase-admin/lib/messaging/messaging-api-request.js:93:30
>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    errorInfo: {
>      code: 'messaging/internal-error',
>      message: 'Internal error encountered.'
>    },
>    codePrefix: 'messaging'
>  } 

I tried changing the auth key, but still getting errors.

Code is very simple

import * as admin from 'firebase-admin'
admin.initializeApp()
async function sendPushNotification(
  tokens: string[],
  title: string,
  body: string
): Promise<admin.messaging.BatchResponse> {
  console.log('sending %s to %d devices', body, tokens.length)
  const message = {
    notification: {
      title: title,
      body: body,
    },
    tokens: tokens,
    apns: {
      payload: {
        aps: {
          sound: 'default',
        },
      },
    },
  }
  return admin.messaging().sendMulticast(message)
}
segfault
  • 5,759
  • 9
  • 45
  • 66

1 Answers1

3

I have been having the same problem: node.js firebase admin SDK sending notifications to iOS occasionally fails with 500/ISE.

It seems specific to, or at least more common with, iOS as during Android development I never had this issue. I contacted Firebase support and here is what they said:

Internal Server Error are usually due to timeouts. Some minor hiccups can't be avoided that's why we recommend developers to implement exponential back-off retry mechanism. You can refer to this StackOverflow discussion for more information on retry-after and exponential back offs.

It seems like a good idea to build in some retry support on my side in any case. I haven't used it before but I like the look of the cockatiel module on npm. I'm planning on going with the retryWithBreaker example given at the start of their README, just with the backoff attempts and breaker set higher, maybe 5 and 20 respectively.

Josh
  • 61
  • 3