Fix retry count in push notifications
In some instances the retry mechanism would get into a busy loop. That's due to the fact that we would fetch some non-retriable notifications but not act on them. This commit fixes the issue by filtering them from the database query and making sure that we at least wait 1 second.
This commit is contained in:
parent
6f088bb5c5
commit
cd21f9b0e2
|
@ -1425,6 +1425,8 @@ func (c *Client) resendingLoop() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.config.Logger.Debug("have some retriable notifications", zap.Int("retryable-notifications", len(retriableNotifications)))
|
||||||
|
|
||||||
for _, pn := range retriableNotifications {
|
for _, pn := range retriableNotifications {
|
||||||
|
|
||||||
// check if we should retry the notification
|
// check if we should retry the notification
|
||||||
|
@ -1443,8 +1445,15 @@ func (c *Client) resendingLoop() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
nextRetry := lowestNextRetry - time.Now().Unix()
|
nextRetry := lowestNextRetry - time.Now().Unix()
|
||||||
|
|
||||||
|
// Give some room, sleep at least a second
|
||||||
|
if nextRetry < 1 {
|
||||||
|
nextRetry = 1
|
||||||
|
}
|
||||||
|
|
||||||
// how long should we sleep for?
|
// how long should we sleep for?
|
||||||
waitFor := time.Duration(nextRetry)
|
waitFor := time.Duration(nextRetry)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
||||||
case <-time.After(waitFor * time.Second):
|
case <-time.After(waitFor * time.Second):
|
||||||
|
|
|
@ -309,7 +309,7 @@ func (p *Persistence) UpdateNotificationResponse(messageID []byte, response *pro
|
||||||
|
|
||||||
func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, error) {
|
func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, error) {
|
||||||
var notifications []*SentNotification
|
var notifications []*SentNotification
|
||||||
rows, err := p.db.Query(`SELECT retry_count, last_tried_at, error, success, public_key, installation_id, message_id,chat_id, notification_type FROM push_notification_client_sent_notifications WHERE NOT success AND error = ?`, protobuf.PushNotificationReport_WRONG_TOKEN)
|
rows, err := p.db.Query(`SELECT retry_count, last_tried_at, error, success, public_key, installation_id, message_id,chat_id, notification_type FROM push_notification_client_sent_notifications WHERE NOT success AND error = ? AND retry_count <= ?`, protobuf.PushNotificationReport_WRONG_TOKEN, maxPushNotificationRetries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue