parse-server-modules / parse-server-sns-adapter

Parse Server SNS Adapter
18 stars 14 forks source link

Error on Android Push: This endpoint is already registered with a different token #10

Open promisenxu opened 7 years ago

promisenxu commented 7 years ago

For the first few pushes to Android device, everything works fine. However, after a few pushes, I got the following error every time a push is sent and no push can be received on Android devices:

ERR! parse-server-sns-adapter  { InvalidParameter: Invalid parameter: This endpoint is already registered with a different token. 
ERR! parse-server-sns-adapter     at Request.extractError (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/protocol/query.js:40:29) 
ERR! parse-server-sns-adapter     at Request.callListeners (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/sequential_executor.js:105:20) 
ERR! parse-server-sns-adapter     at Request.emit (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/sequential_executor.js:77:10) 
ERR! parse-server-sns-adapter     at Request.emit (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/request.js:596:14) 
ERR! parse-server-sns-adapter     at Request.transition (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/request.js:21:10) 
ERR! parse-server-sns-adapter     at AcceptorStateMachine.runTo (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/state_machine.js:14:12) 
ERR! parse-server-sns-adapter     at /app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/state_machine.js:26:10 
ERR! parse-server-sns-adapter     at Request.<anonymous> (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/request.js:37:9) 
ERR! parse-server-sns-adapter     at Request.<anonymous> (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/request.js:598:12) 
ERR! parse-server-sns-adapter     at Request.callListeners (/app/node_modules/parse-server-sns-adapter/node_modules/aws-sdk/lib/sequential_executor.js:115:18) 
ERR! parse-server-sns-adapter   message: 'Invalid parameter: This endpoint is already registered with a different token.', 
ERR! parse-server-sns-adapter   code: 'InvalidParameter', 
ERR! parse-server-sns-adapter   time: 2017-01-28T08:39:57.637Z, 
ERR! parse-server-sns-adapter   requestId: 'c675119e-5328-56df-84e7-40980835090d', 
ERR! parse-server-sns-adapter   statusCode: 400, 
ERR! parse-server-sns-adapter   retryable: false, 
ERR! parse-server-sns-adapter   retryDelay: 5.066305716600228 } 

Environment: Parse Server v2.3.1, SNSPushAdapter v0.0.8. On Heroku.

If I clear all the endpoints in AWS consoles, all pushes work for a few time and then the errors reappear. It seems that every time a new push is sent, a new endpoint for the same token will be created. When you have about 4 endpoints for the same token, this error starts to appear.

This following link seems to discuss this problem: http://docs.aws.amazon.com/sns/latest/dg/mobile-platform-endpoint.html#mobile-platform-endpoint-problems

Would updating the AWS-SDK solve the problem?

rogerhu commented 7 years ago

Yeah creation of an endpoint is supposed to be idempotent, there must be something wrong with the code. Do you have any suggested fixes?

promisenxu commented 7 years ago

@rogerhu I have spent some time reading through the documentation on AWS and some related posts. What you said is right - the createPlatformEndpoint is supposed to be idempotent but for whatever reason, it's actually not for Android. Some posts suggest setting userData and I tried that but still had the same problem.

In the sample code provided by AWS in the link I shared, it seems that AWS want us to store the association between the ARN and device token, instead of calling createdPlatformEndpoint every time. This would entail a rather significant change to how the code currently works and how the push adapter is supposed to work. Are you open to such change?

On another related note, I understand one of the current limitations for the code is that the enable/disable status of an endpoint is not checked nor maintained. This would probably be something that needs to be fixed as well.

rogerhu commented 7 years ago

Can you can confirm that the operation is not idempotent? I've seen it once but not as often. If so, then yes, we need to go the way of storing this association.

Yes, the endpoint should be checked I noticed that when you call create on an endpoint that has been disabled, it automatically updates to enabled.