diff --git a/protocol/pushnotificationclient/client.go b/protocol/pushnotificationclient/client.go index d472261dd..78432b54b 100644 --- a/protocol/pushnotificationclient/client.go +++ b/protocol/pushnotificationclient/client.go @@ -1425,6 +1425,8 @@ func (c *Client) resendingLoop() error { return nil } + c.config.Logger.Debug("have some retriable notifications", zap.Int("retryable-notifications", len(retriableNotifications))) + for _, pn := range retriableNotifications { // check if we should retry the notification @@ -1443,8 +1445,15 @@ func (c *Client) resendingLoop() error { } nextRetry := lowestNextRetry - time.Now().Unix() + + // Give some room, sleep at least a second + if nextRetry < 1 { + nextRetry = 1 + } + // how long should we sleep for? waitFor := time.Duration(nextRetry) + select { case <-time.After(waitFor * time.Second): diff --git a/protocol/pushnotificationclient/persistence.go b/protocol/pushnotificationclient/persistence.go index 793eefd24..272a28889 100644 --- a/protocol/pushnotificationclient/persistence.go +++ b/protocol/pushnotificationclient/persistence.go @@ -309,7 +309,7 @@ func (p *Persistence) UpdateNotificationResponse(messageID []byte, response *pro func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, error) { 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 { return nil, err }