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

Clean up invalid deviceTokens - deleting valid ones as well?

Open oyvindvol opened this issue 8 years ago • 11 comments

Issue Description

I have set the flag PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS = 1 on Heroku. On some occations my users are reporting that push have stopped working, and when I check their Installation object, the deviceToken is undefined. It has worked for them before.

Is it possible that the clean up flag is also un-setting valid deviceTokens, on some occations?

What happens if I don`t set the flag, will the push sending abort when reaching an invalid deviceToken? Or will it just log, and continue sending pushes to valid ones?

Steps to reproduce

Set up environment with versions as described below. Set the flag PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS=1 on Heroku. Use parse-server for a while, and see that some installation objects may get deviceToken=undefined after some time.

Expected Results

Valid deviceTokens are not un-set.

Actual Outcome

Valid deviceTokens may get un-set.

Environment Setup

  • Server

    • parse-server version: 2.7.1
    • Operating System: Heroku
    • Hardware: Heroku
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Heroku
  • Database

    • MongoDB version: mLab via Heroku
    • Storage engine: mLab via Heroku
    • Hardware: mLab via Heroku
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab via Heroku

oyvindvol avatar Jan 16 '18 08:01 oyvindvol

I had a similar issue, please see this post

adammlevy avatar Jan 16 '18 17:01 adammlevy

@adammlevy Thanks. So the solution is removing the clean-up flag? And the ones who have lost their deviceToken already need to re-install?

oyvindvol avatar Jan 16 '18 17:01 oyvindvol

@oyvindvol in iOS, usually you can reaquire the device token easily, by registering again for pysh notifications, it is actually recommended to call the registration method on startup to make sure the token is valid.

flovilmart avatar Jan 16 '18 17:01 flovilmart

@flovilmart Yes, I am calling it on startup. That’s why I found it strange that the affected installations did not get a new deviceToken on startup. They remain undefined..

oyvindvol avatar Jan 16 '18 18:01 oyvindvol

@flovilmart I am testing this now:

  • In parse dashboard I deleted my devicetoken, emptied the column.
  • I run ios app in debug in xcode, didRegisterForRemoteNotificationsWithDeviceToken is getting called.
  • I do like this to update my installation object with the device token (snippet1):
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
  • The device token is not saved to the installation object

Am I doing something wrong here?

Edit: With this code the deviceToken updates in the database/dashboard (snippet2):

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
//[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation setObject:[self convertDeviceTokenToString:deviceToken] forKey:@"deviceToken"];
[currentInstallation saveInBackground];

I have copied the +(NSString *)convertDeviceTokenToString:(id)deviceToken from PFPushUtilities in the Parse-IOS-SDK code.

Would this be harmful in any way?

Edit 2: After furter investigation, the first method (snippet1) now updates with the new device token after doing a [currentInstallation fetch] to get the latest from the server (if any changes occurred from the server/db side).

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation fetch];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];

oyvindvol avatar Jan 22 '18 11:01 oyvindvol

@oyvindvol why did you close the ticket? Have you found a solution?

halavins avatar Feb 13 '18 11:02 halavins

@halvini I got my deviceTokens back when:

  1. Setting the environment variable PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS to 0 on Heroku.
  2. Implementing the code sample in "Edit 2" of my last post (fetching the installation changes from the server before setting the deviceToken again):
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation fetch];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];

oyvindvol avatar Feb 13 '18 11:02 oyvindvol

@oyvindvol , oh, I managed to get my back from MongoDB backup.

But did you find a solution for removing the Bad Device Tokens?

halavins avatar Feb 13 '18 15:02 halavins

@halvini No.

oyvindvol avatar Feb 14 '18 07:02 oyvindvol

I know this is an older thread, but I noticed that the FCM server returns a "NotRegistered" error when sending a push to a device in Do Not Disturb mode. I haven't looked at the parse push code, but if this error results in removing the deviceToken, and you only call register on startup, your app would not receive pushes after DND is turned off on the device.

Also, I think the requirement to call fetch() on the current installation is because the server is removing something (deviceToken) out from under the clients, so the client caches still have a deviceToken and are not marked dirty, so they do not update the server record. This seems messy.

chrisbyers avatar Oct 03 '19 13:10 chrisbyers

FCM server returns a "NotRegistered" error when sending a push to a device in Do Not Disturb mode

@chrisbyers I haven't seen this mentioned in Google Android docs or anywhere else for that matter. It seems pretty counter-intuitive too. Do you have any reference for that?

mtrezza avatar Jun 24 '20 17:06 mtrezza