Skip to content
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

Error 429 (TooManyProviderTokenUpdates) #132

Closed
bmueller opened this issue Apr 24, 2019 · 6 comments
Closed

Error 429 (TooManyProviderTokenUpdates) #132

bmueller opened this issue Apr 24, 2019 · 6 comments

Comments

@bmueller
Copy link

I'm periodically getting status code 429 (TooManyProviderTokenUpdates) back from the push server. This happens every other day or so, for around 100-200 notifications that were all sent at the exact same time. Any idea what might be causing this?

I'm using go version 1.12.4 on Heroku with a single dyno.

Below is the code I'm using to spin up the workers. I currently have up to 50 workers going at once, I'll try reducing that to 20 to see if the issue recurs. But not sure yet whether that is the cause.

Also, does apns2 retry these pushes if this error is returned? Or do I have to handle that myself?

`func collectPush(rw http.ResponseWriter, req *http.Request) {

decoder := json.NewDecoder(req.Body)
var p PushBatch
err := decoder.Decode(&p)
if err != nil {
    panic(err)
}

count := len(p.PushNotifications)
notifications := make(chan *apns2.Notification, 100)
responses := make(chan *apns2.Response, count)

for i := 0; i < 50; i++ {
	go worker(notifications, responses)
}

for _, p := range p.PushNotifications {
	n := &apns2.Notification {
		DeviceToken: p.DeviceToken,
		Topic:       "XXX",
		Payload:     []byte(p.Payload),
	}
	notifications <- n
}

for _, p := range p.PushNotifications {
	res := <-responses		
}

close(notifications)
close(responses)

rw.WriteHeader(200)

}`

@bmueller
Copy link
Author

Still getting this after reducing the number of workers to 20. Any ideas @sideshow?

@bmueller
Copy link
Author

For reference, here's the description for TooManyProviderTokens:

The provider’s authentication token is being updated too often. Update the authentication token no more than once every 20 minutes.

How do I prevent the auth token from updating more often than every 20mins? I have the NewTokenClient call in main() so I don't think I'm just updating this on my own.

@wiggisser
Copy link
Contributor

Do you reuse the client you create with apns2.NewTokenClient(token) or do you create a new client for every notification you send?

@bmueller
Copy link
Author

bmueller commented Sep 7, 2019

Haven't seen this happen again in a while so I'm going to close this.

@pesterhazy
Copy link

@bmueller we're seeing this issue in production again. How did you resolve the issue?

Given that a process may be sending notifications to multiple destinations, we can't reuse the same client for all messages. Is the solution to keep a pool of clients around, one for each token?

@sideshow
Copy link
Owner

sideshow commented Aug 15, 2024

Yes, I believe this error is when you spam apple with too many different Authentication Token's. The token you generate with the token package should be reused if possible, ie make sure you're not generating a new token each time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants