parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Some Push Notifications stuck in SENDING state

Open UnlikelySassou opened this issue 9 years ago • 85 comments

Issue Description

I've recently moved my Parse Server instance to Heroku. I've put my push logic in Cloud Code instead of using client push and I can send and receive push notifications.

My issue is that the status of the push object is stuck at SENDING in Parse Dashboard ("status": "running" on the mongo object) when one of the pushes can't be delivered to an installation.

Example: I send a push to a list of users, but some of them have an installation with no deviceToken configured. Those with a deviceToken receive the push, but the others don't.

That's an expected result, but the push status will stay forever in the SENDING state and I'm not sure if I should worry about it or not.

Note: The push status is changed correctly to SENT if all the Installations have a deviceToken and the number of push sent matches the number of push delivered. Also this behaviour did not occurred when I was using client push.

Steps to reproduce

Send a push to one or more installations with some correctly configured and some with no deviceToken.

Expected Results

Those with a deviceToken receive the push, but the others don't. The push status change to something other than "running" even if some failed.

Actual Outcome

The push object is stuck forever at SENDING in Parse Dashboard ("status": "running" on the mongo object) even is some notifications were delivered.

I'm not sure if this is a big issue and if I should worry about the server trying to send pushes indefinitely.

Environment Setup

  • Server

    • parse-server version : 2.3.5
    • Hardware: Standard-1x (512 MB)
    • Localhost or remote server?: Heroku
  • Database

    • MongoDB version: 3.0.14
    • Hardware: Shared Cluster
    • Localhost or remote server? mLab

Logs/Trace

Example: 3 pushes sent, 1 device received it, 2 failed because of missing deviceToken. Push object now in sending state forever.

2017-02-24T13:59:29.004277+00:00 app[web.1]: info: Ran cloud function sendPushToRecipients for user xVOydE7ugH with:
2017-02-24T13:59:29.004293+00:00 app[web.1]:   Input: {"recipients":["dpVQ9ZQypH","Vs3OADhHnS"],"data":{"alert":"test.","NTYPE":"NEW","badge":1,"sound":"default"},"appVersion":"1"}
2017-02-24T13:59:29.004295+00:00 app[web.1]:   Result: "Push Sent!" functionName=sendPushToRecipients, recipients=[dpVQ9ZQypH, Vs3OADhHnS], alert=test., NTYPE=NEW, badge=1, sound=default, appVersion=519, user=xVOydE7ugH

_PushStatus object

{
    "_id": "ZieiF3w31X",
    "pushTime": "2017-02-24T13:59:28.981Z",
    "query": "{\"currentProfile\":{\"$inQuery\":{\"where\":{\"objectId\":{\"$in\":[\"dpVQ9ZQypH\",\"Vs3OADhHnS\"]}},\"className\":\"Profile\"}},\"appVersion\":\"1\"}",
    "payload": "{\"alert\":\"test",\"NTYPE\":\"NEW\",\"badge\":1,\"sound\":\"default\"}",
    "source": "rest",
    "status": "running",
    "numSent": 1,
    "pushHash": "882c51079dfab452aed1f146fedb37a2",
    "_wperm": [],
    "_rperm": [],
    "_acl": {},
    "_created_at": {
        "$date": "2017-02-24T13:59:28.981Z"
    },
    "_updated_at": {
        "$date": "2017-02-24T13:59:29.066Z"
    },
    "count": 3,
    "sentPerType": {
        "ios": 1
    }
}

Cloud Code

Parse.Cloud.define("sendPushToRecipients", function(request, response) {
  var profileQuery = new Parse.Query("Profile");
  profileQuery.containedIn("objectId", request.params.recipients);
  var installationQuery = new Parse.Query(Parse.Installation);
  installationQuery.matchesQuery("currentProfile", profileQuery);
  installationQuery.equalTo("appVersion", request.params.appVersion);
  
  Parse.Push.send({
    expiration_interval:600,
    where: installationQuery,
     data: request.params.data
    }, {
      success: function() {
        response.success("Push Sent!");
      },
      error: function(error) {
        response.error("Push failed: " + error);
      },
      useMasterKey: true
    });
});

UnlikelySassou avatar Feb 24 '17 14:02 UnlikelySassou

@flovilmart It's the same problem that I raised in #3080

adirgan avatar Feb 24 '17 18:02 adirgan

@adirgan Yes, it seems to be the same issue. My Parse Dashboard push page is very similar: the push status is changed correctly to SENT only if all the _Installation objects targeted by the push have a deviceToken. No matter if it's sent to a channel or specific recipients.

From what I've read, is it safe to assume that all the push notifications that have an audience (with valid deviceToken) are actually sent anyway and that it is just an issue with Parse Server not updating _PushStatus correctly because of the faulty _Installation objects?

I'm worried that this SENDING state means some performance issue or something bad with the server. If it is just a state update issue, I can live with that for now.

UnlikelySassou avatar Feb 24 '17 18:02 UnlikelySassou

@iOSassou Do not worry that the push messages arrive without problem and does not affect the performance at all, it is only an error to update the status.

adirgan avatar Feb 24 '17 18:02 adirgan

@adirgan Thank you

UnlikelySassou avatar Feb 24 '17 18:02 UnlikelySassou

@adirgan sorry, I believe the ball was dropped on my side on that... 🙇 I need to investigate further. But the state reporting has proven to be quite unreliable in general :/

flovilmart avatar Feb 24 '17 18:02 flovilmart

@flovilmart Do not worry, while the problem is only visual and not performance is fine.

adirgan avatar Feb 24 '17 18:02 adirgan

@flovilmart @adirgan Yes. As long as it is not really affecting the app, I think it's fine (maybe just a bit confusing).

UnlikelySassou avatar Feb 24 '17 18:02 UnlikelySassou

Yeah that should be fixed however :/ that's clearly a regression

flovilmart avatar Feb 24 '17 19:02 flovilmart

@flovilmart Have found the same issue here after upgrading to the latest version. Any clues in how to solve that?

felipeandradebezerra avatar Mar 13 '17 13:03 felipeandradebezerra

Need to add a small check to exclude installations without deviceToken from the query

flovilmart avatar Mar 14 '17 13:03 flovilmart

upgrade to apn 2.x is really the only solution for proper tracking.

jeacott1 avatar Mar 15 '17 01:03 jeacott1

Also there is a bug that I uncovered that improperly forwards the deviceType on successful pushes.

flovilmart avatar Mar 15 '17 01:03 flovilmart

@flovilmart All iOS pushes are not being send, need to downgrade to Parse-Server 2.3.1 to get it working properly.

felipeandradebezerra avatar Mar 15 '17 12:03 felipeandradebezerra

@felipemobile are they not sent or just marked 'sending'?

flovilmart avatar Mar 15 '17 12:03 flovilmart

Not sent @flovilmart

felipeandradebezerra avatar Mar 15 '17 13:03 felipeandradebezerra

Maybe a conflict after the #3264, #3080 improvements?

felipeandradebezerra avatar Mar 15 '17 13:03 felipeandradebezerra

Uhm, not sent is more problematic than just not marked as Sent, can you provide more details, logs etc... to debug that issue? There was an underlying bug in the push adapter that prevented the push status to be properly reported.

flovilmart avatar Mar 15 '17 14:03 flovilmart

Sending a single push don't seem to cause the issue

flovilmart avatar Mar 15 '17 14:03 flovilmart

@flovilmart do you need any special type of log to debug that issue?

felipeandradebezerra avatar Mar 15 '17 14:03 felipeandradebezerra

Setting VERBOSE=1 should log all see https://github.com/parse-server-modules/parse-server-push-adapter/blob/master/src/index.js

flovilmart avatar Mar 15 '17 16:03 flovilmart