javapns-jdk16
javapns-jdk16 copied to clipboard
Same message received as Multiple Notifications in Single device.
While sending same message to group of devices, in particular scenario few devices got multiple Notifications.
Assume that using following method, the application send same payload to 100 devices.
public PushedNotifications sendNotifications(Payload payload, List<Device> devices) throws CommunicationException, KeystoreException {
PushedNotifications notifications = new PushedNotifications();
for (Device device : devices)
notifications.add(sendNotification(device, payload, false, SEQUENTIAL_IDENTIFIER));
stopConnection();
return notifications;
}
After sending message to 50 devices, assume that 51st message is failed and breached the retry attempts; This will set transmissionCompleted as false for 51st Notification. From 52nd message onwards everything goes proper upto 100. Before closing the connection via stopConnection method, processed failed notifications method is called. Once response received from APNS, it will iterate through LinkedHashMap pushedNotifications and see which one is unsuccessful. Since the transmissionCompleted is false for 51st message, following check will be satisfied if (foundFirstFail || !notification.isSuccessful()) {, it will skip the 51st Message and from 52nd message onwards it will do the retry. This will send the same message to the devices from 52nd to 100.
Solution - There are various ways to fix this. Simple way is PushedNotification Object should not be considered in pushedNotifications hashMap, once it is failed in sending the message.
I was on the same bug. Thank you pointing out the right direction. Is this bug considered to be solved in near future? Else @erlangrobot can you share your solution as source so that I manually change the source for the time being. Because this is a huge issue.
I settled on this simple change
for (PushedNotification notification : pushedNotifications.values()) {
if (notification.getException() == null && !notification.isSuccessful()) {
notificationsToResend.add(notification);
}
}
For anyone interested.