-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Is cleanup invalid device tokens safe to use? #6052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@mrmarcsmith It seems you have been digging into the push topic with other issues you've opened. Do you have any feedback on |
@mtrezza I haven’t looked into this issue yet but I’ll see if I have time to dive in while I still have the push system fresh in my mind. Off the top of my head I would imagine the first step would be to write a failing test which would involve mocking the APNS, which would involve bouncing some different types of requests off of the APNS Servers to see how they respond. From the issue you posted I’m thinking one solution could be to keep track of the types of error responses for the different types of certificates and only remove deviceTokens where error responses from ALL certificates is “Bad Device Token” that way if one returns a temporary error we don’t remove it. What do you think? |
I think the basic issue is mocking the APNS, it is a black box, except for what is documented anyway. Therefore I'm looking to gather some feedback on production usage in this thread. I think rather than testing against all certificates I would put forth the motion to deprecate specifying multiple Apple certificates. Apple offers a single push certificate for sandbox and production just like Android, so it would make sense to reflect that in the adapter. |
In a couple of our apps we use two different app identifiers, one for our store version and one for our enterprise version (com.bla.app1-Store & com.bla.app1-Enterprise) therefore we need two production push certificates for one app, but the appIdentifer is stored in the installation so we would could just ensure that parse doesn’t retry on an installation that doesn’t match its appIdentifer. What about this solution? |
And of course in addition to the warning, we also actually disable the cleanup if they have multiple certs with the same app identifiers |
@mrmarcsmith Interesting, does parse server officially support multiple apps in 1 deployment? How to you make sure the proper push certificate is used for the proper app ID? |
@mtrezza to clarify, these are not two separate “apps”. Both have identical “Parse Server ApplicationIds”, identical iOS Client code and use the same cloud code. The only difference is how they are distributed and how apple treats them.
The configuration for Parse APNS here requires a “bundleId” to be provided with the certificate. And the “bundleId” field will match the corresponding “parse-default” field “appIdentifier” in the _Installation class. In theory, Parse should NEVER attempt sending a enterprise installation a push using the Store certificate (and visa-versa) because the bundleId’s don’t match. Which is why it sould be safe to allow multiple certificate to co-exist as long as the have different bundleId’s |
Correct, as long as you specify a So how about adding your waning and deprecate the production/development flag in the adapter and issue an additional deprecation warning? Production and development environments are usually separated anyway, so I don’t see a good reason to keep this entanglement. |
In the case that they want to connect to the development APNS server isn’t it a different apple URL? That’s just my initial hunch on why we asked for the production flag in the config, I’m running out the door so I don’t have time to dig into the adapter code to confirm |
It is a different URL, but the If The actual URL is set in node-apn depending on the node environment:
With the "universal" Apple push certificate the I am still unsure of how invalid device tokens are determined. When adding multiple certificates without parse-server/src/StatusHandler.js Line 260 in cf6e79e
|
DeviceRemoval happens if APNS replies with “invalid deviceToken” error. here |
That is how it works in principle, but I couldn’t figure out yet if each result that is evaluated is
In case of 1) a device token would be incorrectly removed if it fails with any tried certificate. In case of 2) a device token would correctly be removed if it fails with all tried certificates. |
@mtrezza Should we encourage users to use a single key instead of certificates? This is an added benefit that they don’t expire so you don’t have to renew them.
|
@dplewis That's a fair suggestion. Apple says:
@mrmarcsmith Would that also cover your use case of multiple app IDs? |
As long as we can still do multiple keys like so I’m fine.
The “problem” i face is apple requires a completely different Apple ID for enterprise and store meaning i have to use 2 “keys” because they are completely isolated account by design. “All of your apps” implies “All your app under this Apple ID” of which I have 2. |
@mrmarcsmith Seems to be an edge case but makes sense for parse server to support this. So migrating from multiple certs to multiple key won't solve the issue. I see two PRs (in order of priority):
ad 1) ad 2)
|
@mtrezza here’s a idea, we could disallow multiple certificate/keys with duplicate topics. Then just confirm on the adapter side we aren’t attempting to send pushes for topics that don’t match the appIdentifier (which those pushes would never succeed anyways). |
That would be a breaking change, possibly for many users, because historically it was common / required to have a separate development and production certificate for the same topic:
That already happens: Again, to ensure the token clean-up works, we only need to clean up the token if it failed for all certs rather than if it failed for any cert when the adapter uses multiple certs. |
I'm back at this issue, preparing a PR to ensure the feature is fit for production. Current processAPNS:
FCM:
Result handling in parse server:
IssuesBottom line, the potential issue of incorrectly cleaning up valid device tokens only exists for APNS. The following scenarios are possible: a) Push to correct provider fails with some "temporarily unavailable", and retry push to incorrect provider fails with "token invalid". b) Push to correct provider fails because certificate is expired, and retry push to incorrect provider fails with "token invalid". c) Push to incorrect provider fails because provider d) It is currently allowed to add APNS providers without Just to be sure, I re-checked, whether the error codes relevant to removal of device token are correct, and yes, they are:
Bottom bottom line, issues are only possible if:
b) There is more than 1 APNS provider and at least one has no
Solutionad a) Disallow multiple APNS adapters with same topic.
ad b) Disallow APNS adapter without topic.
Both changes are breaking changes, but the effort required by the user is just to remove one adapter from config file if there are multiple and download the universal certificate. |
@mrmarcsmith Does the proposed solution above still allow your scenario of using an enterprise cert and regular cert for the same parse app ID? @dplewis Should I start a PR? |
Go for it! You have done the research on this topic. I’ll help as much as I can. |
A recent observation: Cleaning up device tokens for FCM works as expected, but it doesn't seem to work well for APNS. Device tokens of uninstalled iOS apps are not removed because the APNS push response is successful, as by the push-adapter verbose log. I confirmed this with 2 year old APNS device tokens and recent ones. I have only seen APNS device tokens removed for incorrect environment, e.g. sending a sandbox token to the production APNS endpoint. The issue seems to be the APNS. See also |
Applied label "feature" because this thread came to be about bringing the device token clean-up from its experimental status to a standard feature. The analysis in this thread should provide the the required basis to do this. |
@mtrezza I realize all of the info is probably in this thread, but was this ever resolved in any way? I'd love to use this feature on a 6-year-old app with tons of "BadDeviceToken" error messages whenever there is a push sent out. |
@cr0ybot As far as I'm aware that issue has not been touched since then. The behavior should still be the same. So you could use it, considering the caveats. I've quickly revisited my previous comments here and it seems that if you use a universal APNS certificate for sandbox + production and thus have only one certificate entry in the push adapter configuration for APNS, there shouldn't be any issue. I don't see how we could solve the remaining issue, that can probably only be solved on the APNS side. |
Issue Description
Parse Server v2.6.2 introduced a feature to clean up invalid device tokens. There have been issues reported where valid device tokens have been removed, some of which have been closed without conclusion, notably:
The root cause for these issues could be parse-community/parse-server-push-adapter#87 (comment), but because the issues have not been further investigated it's hard to tell.
The feature is still flagged and not in the docs, which makes me think there are still doubts about its functionality.
Is
PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS
safe to use?Is anyone using the feature in a production environment and can give feedback?
The text was updated successfully, but these errors were encountered: