SendForEachMulticast in scheduled cloud function mostly failing

123 views
Skip to first unread message

habitoti

unread,
Jul 15, 2024, 10:44:46 AMJul 15
to Firebase Google Group
Hi,

I have a scheduled cloud function that collects nightly a bunch of turn reminders for my game to be sent as push notifications. It returns an array of promises, each executing SendForEachMulticast (v1) to all the tokens of the devices a player owns. This produces usually around 40 promises being returned. Rarely all of them execute properly, sometimes just a few (maybe 1-3), most often however none at all (all tokens are registered & valid!). They all end up in timeout of 15secs then.
I only lately noted that this seems to be an issue now. It worked always properly a few month (actually years) ago . Is there any new restriction on push notifications being sent from a scheduled function? Is there any better way of making sure that those notifications are sent properly once a night? I am sending much more notifications (with actually the exact same sending code & tokens) around the clock on Realtime-DB changes, and never see any error there.

Thanks for any hints,
    habitoti

Joe Spiro

unread,
Jul 19, 2024, 11:51:41 AMJul 19
to Firebase Google Group
Please inspect what specific errors are returned:

Each call to  Messaging.sendEachForMulticast() returns a promise returning a BatchResponse that contains an array of SendResponse. These can be iterated through to determine what happened to each individual send.

It is likely though not entirely certain that some portion of this may be resultant from exceeding your send quota as described in Throttling and quotas. Methodologies to alleviate this are available in Best practices when sending FCM messages at scale.

Please message when you find out more and whether the above was helpful.

habitoti

unread,
Jul 22, 2024, 10:30:47 AMJul 22
to Firebase Google Group
Some users usually forget about making their moves in multiple different concurrent games within the app, so I produced as many reminder notifications with the same title and body text ("It's your turn in a game") after some time. The actual game was referred to by a separate payload that was processed when clicking the notification to directly jump to the respective game. As it turns out, Firebase doesn't seem to like it when I schedule multiple notifications for the same recipient with just different payloads. I am not even talking about hundreds of them -- just a few "redundant" notifcations (not considering actual payload) seem sufficient to blast the whole (or most of the) batch of promises returned from the scheduled function. 
I changed it now to just produce one notification at most per user (which is fair, as he will see the other open games anyways once he jumps to the game app...). And guess what...no more issues whatsoever. All notifications are sent properly. And it was not about quota, because it now also works properly with even more total notifications per run -- as long as they are all targeted to different players.

Reply all
Reply to author
Forward
0 new messages