Skip to content

Temporary fix for sending batched notifications with one or more wrong registration id #823

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ node_modules/
.vs/

settings.json
/PushSharp.1.0.6.nupkg
/PushSharp.4.0.10.1.nupkg
/PushSharp.Core.1.0.6340.27706.nupkg
/PushSharp.Apple.1.0.6340.27706.nupkg
Binary file added PushSharp.4.0.11.nupkg
Binary file not shown.
25 changes: 20 additions & 5 deletions PushSharp.Apple/ApnsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ async Task SendBatch ()
// Let's store the batch items to send internally
var toSend = new List<CompletableApnsNotification> ();

while (notifications.Count > 0 && toSend.Count < Configuration.InternalBatchSize) {
var n = notifications.Dequeue ();
toSend.Add (n);
lock (notificationBatchQueueLock)
{
while (notifications.Count > 0 && toSend.Count < Configuration.InternalBatchSize)
{
var n = notifications.Dequeue ();
toSend.Add(n);
}
}


Expand Down Expand Up @@ -154,13 +158,24 @@ async Task SendBatch ()
}

foreach (var n in toSend)
sent.Add (new SentNotification (n));
sent.Add(new SentNotification(n));
}

} catch (Exception ex) {
Log.Error ("APNS-CLIENT[{0}]: Send Batch Error: Batch ID={1}, Error={2}", id, batchId, ex);
var errorNotificationToSend = new List<CompletableApnsNotification>();

foreach (var n in toSend)
n.CompleteFailed (new ApnsNotificationException (ApnsNotificationErrorStatusCode.ConnectionError, n.Notification, ex));
{
if (!n.Notification.IsDeviceRegistrationIdValid())
errorNotificationToSend.Add(n);
else
notifications.Enqueue(n);
}

foreach (var n in errorNotificationToSend)
n.CompleteFailed(new ApnsNotificationException(ApnsNotificationErrorStatusCode.ConnectionError, n.Notification, ex));

}

Log.Info ("APNS-Client[{0}]: Sent Batch, waiting for possible response...", id);
Expand Down