0

I'm looking to set up a simple Node.JS server which will listen for requests from an app I'm building and from it build a "send message" request to Firebase Cloud Messaging (as stated here: https://firebase.google.com/docs/cloud-messaging/send-message) so that a push notification is sent out to relevant client-side apps. In order to do this one needs to make use of the Firebase Admin SDK.

On Google's Firebase Cloud Messaging documentation under "Server Environments" (https://firebase.google.com/docs/cloud-messaging/server), it's said that running the Firebase Admin SDK requires a server environment which is able to handle requests and resend them using exponential back off. In this case I guess using exponential back off means that the "send message" request to Firebase Cloud Messaging must be retried using an exponential back off algorithm.

It's not said in the documentation however if the Node.JS Firebase Admin SDK already supports such exponential back off functionality or if I have to implement it on my own when using aspects of the Admin SDK.

According to an earlier Stack overflow post (Firebase Admin SDK Java Backoff/retry) the Java SDK does support exponential back off, but I'm not sure whether the Node.JS one does.

Perturbative
  • 83
  • 1
  • 2
  • 10
  • What specific backoff behavior are you looking for, and for what Firebase product? Please edit the question to be clear. – Doug Stevenson Jan 09 '23 at 01:39
  • I'll note also for questions like this (does X support Y), you're better off posting to [firebase-talk](https://groups.google.com/g/firebase-talk) which is monitored by Firebase staff and likely to yield more authoritative answers. – Doug Stevenson Jan 09 '23 at 01:41
  • @DougStevenson I've just updated the question, also thanks for the information! – Perturbative Jan 11 '23 at 07:15

1 Answers1

3

firebaser here

The default retry configuration in the Firebase Admin Node.js SDK automatically retries up to 4 times on connection reset, timeout, and HTTP 503 errors. If the error response contains Retry-After header, the default retry config respects that, too.

In the default config, the backOffFactor is set to 0.5. This results in the exponential retry pattern of 0s, 1s, 2s, and 4s.

/**
 * Default retry configuration for HTTP requests. Retries up to 4 times on connection reset and timeout errors
 * as well as HTTP 503 errors. Exposed as a function to ensure that every HttpClient gets its own RetryConfig
 * instance.
 */
export function defaultRetryConfig(): RetryConfig {
  return {
    maxRetries: 4,
    statusCodes: [503],
    ioErrorCodes: ['ECONNRESET', 'ETIMEDOUT'],
    backOffFactor: 0.5,
    maxDelayInMillis: 60 * 1000,
  };
}

Reference to code in documentation

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Is there a way to override this `defaultRetryConfig()` to support the `messaging/internal-error` error? This error seems to be a 500 error. – Ben Aug 02 '23 at 11:10