question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Program doesn't terminate when running FCM.sendToDevice in nodejs.

See original GitHub issue

[READ] Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository file a Github issue.
    • If this is a feature request make sure the issue title starts with “FR:”.
  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general Firebase discussion, use the firebase-talk google group.
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Mac OS High Sierra (10.13.1)
  • Firebase SDK version: firebase: (^4.5.1)
  • Library version: firebase-admin (^5.4.2)
  • Firebase Product: FCM / admin.messaging()

[REQUIRED] Step 3: Describe the problem

NodeJS program doesn’t terminate after running FCM command.

Steps to reproduce:

  • save the following code as: fcm-test.js
  • run the code with

node fcm-test.js

  • In my enviroment, it’ll not stop untill you forcefully stop it by pressing CTRL+C.

Relevant Code:

const admin = require('firebase-admin');
const serviceAccount = require("../../../service-accounts/production.json");
const registrationTokens = require('./tokens');
// ["someShortString1:someLongString1", "someShortString2:someLongString2", ...];
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
})
const body = 'body';
const title = 'title';
const payload = {
  data: {
    body,
    title
  },
  notification: {
    body,
    title
  }
}
const fcm = admin.messaging();
const printJSON = (thing) => { console.log(JSON.stringify(thing, null, 2))};
fcm.sendToDevice(registrationTokens, payload).then(printJSON).catch(printJSON);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dandvcommented, Mar 19, 2019

You need to call app.delete() if you wish to ensure graceful termination of the process.

How was the developer supposed to know they had to call app.delete()?

1reaction
hiranya911commented, Dec 8, 2017

Given that you’re calling res.send() in each possible case, I believe it’s fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Program won't exit when call to Firebase Cloud Messaging ...
Currently, the problem is when I call firebase.admin.messaging().sendToDevice , my app never ends its execution. Here is the code : main.js :
Read more >
Build app server send requests | Firebase Cloud Messaging
Using the Firebase Admin SDK or FCM app server protocols, you can build message requests and send them to these types of targets:....
Read more >
Send push notifications to Android devices using Firebase ...
In this tutorial, you create a blank Android app that receives push notifications by using Firebase Cloud Messaging (FCM).
Read more >
firebase-admin.Messaging.sendToDevice JavaScript and ...
sendToDevice (registrationToken, payload, options) ... [END function_get_token] //[START pushNotification] function pushNotification(deviceID, accessToken, ...
Read more >
Cloud Messaging | FlutterFire
FCM via APNs does not work on iOS Simulators. ... Terminated, When the device is locked or the application is not running. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found