Failure encountered while attempting to process request: unable to establish connection due to refusal to connect

I have a cloud function that triggers every minute, sending push notifications to users

export const sendScheduledNotifications = functions
  .region(REGION)
  .runWith({
    timeoutSeconds: 540,
  })
  .pubsub.schedule("* * * * *")
  .timeZone("Europe/Amsterdam")
  .onRun(async (_) => {
    const scheduledNotifications = await getNotificationsAfterDate(Date.now());

    const promises = [];

    if (scheduledNotifications.length > 0) {
      const userIds = scheduledNotifications.map((notification) => notification.userId);
      const users: AppUser[] = userIds.length == 0 ? [] : await userRepo.listUsers("id", "in", userIds);

      for (const notification of scheduledNotifications) {
        const user = users.find((user) => user.id === notification.userId)!;
        promises.push(sendScheduledNotification(notification, user));
      }
    }

    await Promise.all(promises);
  });

However, I am encountering the following error in the Firebase console

sendScheduledNotifications
Error: Error while making request: connect ECONNREFUSED XXX.XXX.XX.XX:XXX. Error code: ECONNREFUSED
    at FirebaseAppError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:44:28)
    at FirebaseAppError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:90:28)
    at new FirebaseAppError (/workspace/node_modules/firebase-admin/lib/utils/error.js:125:28)
    at /workspace/node_modules/firebase-admin/lib/utils/api-request.js:211:19
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async sendScheduledNotification (/workspace/lib/index.js:1024:5)
    at async Promise.all (index 0)
    at async /workspace/lib/index.js:973:5 

The sendScheduledNotification function looks like this

 sendMulticast(tokens: string[], notificationData: PushNotificationData): Promise<admin.messaging.BatchResponse> {
    const data: admin.messaging.MulticastMessage = {
      data: { data: JSON.stringify(notificationData) },
      tokens: tokens,
      android: {
        priority: "high",
      },
      apns: {
        payload: {
          aps: {
            contentAvailable: true,
          },
        },
        headers: {
          "apns-push-type": "background",
          "apns-priority": "5",
          "apns-topic": "io.flutter.plugins.firebase.messaging",
        },
      },
    };

    return this.messagingInstance.sendMulticast(data);
  }

What could be causing this issue?

Answer №1

ERROR OCCURRED is a notification that Node sends when the desired system or service is currently unavailable:

ERROR OCCURRED (Connection error): The connection was rejected because the target system actively denied it. This typically happens when attempting to connect to an inactive service on a remote host.

Check if your functions are successfully connecting to the iOS/Android notification services. Also, explore other potential causes of this issue. If you're using the function emulator for local testing, ensure that the emulator is running. Additionally, be aware of any ongoing issues with Firebase Cloud Messaging in their service status.

https://i.sstatic.net/example.png

If the error persists, monitor changes in the service status. Furthermore, as mentioned in this related discussion, functions created under Firebase's free tier may not support outbound connections, leading to this particular error message.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in Visual Studio with Angular 2 build: 'Promise' name not found

I recently started exploring Angular2 and followed the instructions provided in this quickstart guide: https://angular.io/guide/quickstart Everything seems to be working well after running npm install, but now I want to work on it within Visual Studio usi ...

What are the steps for integrating Angularfire2 into an Angular application?

Trying to integrate Angularfire2 into a fresh Angular project, but encountered an issue while following the official documentation. This is the guide I followed Upon reaching step 7 - Inject AngularFirestore, console errors were displayed: https://i.sst ...

How can you ensure an interface in typescript 3.0 "implements" all keys of an enum?

Imagine I have an enum called E { A = "a", B = "b"}. I want to enforce that certain interfaces or types (for clarity, let's focus on interfaces) include all the keys of E. However, I also need to specify a separate type for each field. Therefore, usi ...

Calling synchronous methods in Typescript

Hello Nativescript Team, I seem to be stuck with making method calls in my code. Could you please provide me with guidance on how to implement synchronous method calling in Nativescript + Angular? import { Component, OnInit, AfterContentInit } from " ...

Retrieve the matching values from a JSON object by filtering it with an array, then create a new JSON object containing only

var structureInfos = [{ name: 'HMDB0006285', identifier: 'Six two eight 5' }, { name: 'HMDB0006288', identifier: 'Six two double eight'}, { name: 'HMDB0006293& ...

Experimenting with TypeScript code using namespaces through jest (ts-jest) testing framework

Whenever I attempt to test TypeScript code: namespace MainNamespace { export class MainClass { public sum(a: number, b: number) : number { return a + b; } } } The test scenario is as follows: describe("main test", () ...

typescript create object with immutable property already set

Can you create an object literal in JavaScript and define its interface with read-only properties simultaneously? For instance let obj = { readonly prop1: 'hello', readonly prop2: 'world' } ...

Encountering ExpressionChangedAfterItHasBeenCheckedError in Angular 17 even after invoking detectChanges method

I'm encountering a minor problem with Angular and its change detection mechanism. I have created a simple form where additional input fields can be added dynamically. However, every time I click the add button, an ExpressionChangedAfterItHasBeenChecke ...

What causes a folder to disappear after rerunning in nest.js?

When working on my project using nest.js in MacOS Sonoma, I encountered a problem where the image folder src/products/images gets deleted after every project rerun (npm start). The images are saved like this: for (const image of images) { const fileName ...

The database reference provided was not identified

Within my for loop, I am creating seats and checking if they are already registered in the database. To achieve this, I have implemented a method called look within the two nested loops: for (i = 0; i < maxRow; i++) { for (j = 0; j < maxColu ...

What could be causing the vue-property-decorator @Emit to malfunction in my Vue TypeScript file?

I am currently working with Typescript and Vuejs, where I have a child component called child.component.tsx import Vue from 'vue'; import Component from 'vue-class-component'; import { Emit } from 'vue-property-decorator'; ...

How can I modify the pristine state of NgModel in Angular 2 using code?

Whenever you update the NgModel field, it will automatically set model.pristine to true. Submitting the form does not change the "pristine" status, which is expected behavior and not a bug. In my situation, I need to display validation errors when the fo ...

Finding out the nature of nullable attributes within an object: How can it be done?

I'm facing an issue with saving incomplete forms where I have a form being filled out by a user and I wish to allow the form to be saved even if it's not fully complete. Before sending the object to my API, I need to set any null attributes to e ...

How can I prevent the enter key from working with Twitter Typeahead?

Is there a way to prevent the enter key from being pressed on an element within Twitter Typeahead's dropdown feature while using Angular with Typescript? I attempted to utilize preventDefault() when event.keycode === 13 on the ng-keydown event for th ...

Step-by-step guide on building a personalized rxjs operator using destructured parameters

I am in the process of developing a unique RxJS filter operator that requires a destructured array as a parameter. Unfortunately, TypeScript seems to be throwing an error related to the type declaration: Error TS2493: Tuple type '[]' with a len ...

I am facing an issue where the conversations entered by the user and those generated by the AI are not being stored in my Postgres database within my next.js application

Whenever a question is posed to the AI and a response is provided, the issue arises where the information is not getting saved in the database. Despite including console.log statements in the route.ts file indicating that messages from both the AI and th ...

Visual Studio Code's IntelliSense feature fails to properly recognize the Python syntax within the .env file

Initially, IntelliSense functioned correctly when I began using Visual Studio Code for Python. However, after installing TypeScript, IntelliSense no longer seems to recognize the syntax I am using in my .ENV file. For instance, when I enter export TEST = ...

Unable to execute the Vite project

I ran into an issue with my Vite project yesterday. I closed it and now that I have reopened it, the 'npm run dev' command is throwing an error. My project is built using Vite with React and TypeScript. Attached is a screenshot of the error mess ...

The bidirectional bindings within the component are malfunctioning

I just started learning Angular and I'm currently working on a small project. After following tutorials on two-way bindings, I attempted to implement it in my project. However, when I try to set values in the HTML for my component, it doesn't see ...

Leveraging _.some in lodash

I'm working on a Typescript code where I need to check if any items in one array are present in another array. Although I am new to lodash, I thought of using _.some for this task. However, the code is currently returning false when I expected it to r ...