bharathi91 / javapns

Automatically exported from code.google.com/p/javapns
0 stars 0 forks source link

Duplicate sending #161

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

Today many users complain that receive duplicated notifications after several 
hours.

2012-12-26 09:37:10 
[javapns.notification.PushNotificationManager]-[DEBUG(JavaPNS standalone 
notification thread in QUEUE mode)] Reading responses
2012-12-26 09:37:10 
[javapns.notification.PushNotificationManager]-[DEBUG(JavaPNS standalone 
notification thread in QUEUE mode)] Found 115 notifications that must be re-sent

Server run at Linux. 

Original issue reported on code.google.com by zephyr....@gmail.com on 26 Dec 2012 at 11:00

GoogleCodeExporter commented 8 years ago

2012-12-26 09:37:14 
[javapns.notification.PushNotificationManager]-[DEBUG(JavaPNS standalone 
notification thread in QUEUE mode)] Found 0 notifications that must be re-sent
2012-12-26 09:37:14 
[javapns.notification.PushNotificationManager]-[DEBUG(JavaPNS standalone 
notification thread in QUEUE mode)] No notifications remaining to be resent

2012-12-26 09:37:47 
[javapns.notification.PushNotificationManager]-[DEBUG(JavaPNS standalone 
notification thread in QUEUE mode)] Reading responses
2012-12-26 09:37:47 
[javapns.notification.PushNotificationManager]-[DEBUG(JavaPNS standalone 
notification thread in QUEUE mode)] Found 115 notifications that must be re-sent

Original comment by zephyr....@gmail.com on 26 Dec 2012 at 11:24

GoogleCodeExporter commented 8 years ago
The "automatic re-send" feature was created to deal with a rather strange APNS 
behavior that was observed a long time ago:  during a given connection, any 
invalid push notification that triggers an error-response packet apparently 
causes APNS to stop processing all push notifications streamed after that first 
invalid one.  Thus, if an error-response packet was received, we would have to 
try again all following notifications.

See http://code.google.com/p/javapns/issues/detail?id=69

If Apple changed the behavior recently, this would have to be confirmed and our 
re-send feature would have to be disabled.

Original comment by sype...@gmail.com on 5 Feb 2013 at 7:43

GoogleCodeExporter commented 8 years ago
Are you still experiencing this issue?  or is anyone else experiencing it?

Original comment by sype...@gmail.com on 1 Mar 2013 at 5:20

GoogleCodeExporter commented 8 years ago
I have the same problem, when I send a message to the APNS server, but my 
iphone APNS two push message is received

Original comment by szf881...@163.com on 28 Mar 2013 at 3:48

GoogleCodeExporter commented 8 years ago
I have same problem too. Some customers says that same notification comes 
multiple times but the date+time is old in notification center. Is there any 
solution? Or must we disable automatic resend feature for a while

Original comment by erc...@gmail.com on 8 May 2013 at 7:47

GoogleCodeExporter commented 8 years ago
I have the same issue too.  

Original comment by gianni.s...@gmail.com on 8 May 2013 at 7:51

GoogleCodeExporter commented 8 years ago
Could you please solve this issue of first priority. Some of our customers are 
complaining everyday about old notifications.

Original comment by erc...@gmail.com on 9 May 2013 at 6:31

GoogleCodeExporter commented 8 years ago
Is there an update on this issue?  I noticed today that our 
NotificationThread's were happily sending away long after the last user had 
received their notification.  I didn't have detailed enough error logging 
turned on in our production servers so I can't say for sure why the threads 
were still sending; but this is new behaviour that started in the last week or 
two, with no code changes on our side.  This issue looked relevant, so I'm 
wondering if there's been some investigation and an update?

Original comment by rthor...@gmail.com on 23 May 2013 at 10:50

GoogleCodeExporter commented 8 years ago
I had disabled resend feature, this is a fatal bug!

Original comment by heruim...@gmail.com on 29 May 2013 at 7:35

GoogleCodeExporter commented 8 years ago
Does disabling resend feature solve duplicate sending?

Original comment by erc...@gmail.com on 29 May 2013 at 9:25

GoogleCodeExporter commented 8 years ago
I'm having the same issue.  People receiving notifications repeatedly, but not 
all users.  Most of our reports are that whenever a new notification is sent, 
it's received, but then previous notifications reappear as well.  Any ideas on 
how to fix?

Original comment by chris.mc...@gmail.com on 23 Aug 2013 at 6:53

GoogleCodeExporter commented 8 years ago
Is there a solution to this bug yet, except disabling resend feature?
Its a high priority bug in my app and needs to be fixed asap.

Original comment by sicilia...@gmail.com on 17 Oct 2013 at 3:08

GoogleCodeExporter commented 8 years ago
The Error Handling and resending feature is causing the duplicate pushes. 
Notifications with a exception will trigger a resend off all following messages.
Instead only notifications with an apple response should trigger a resend of 
the following messages.

Testcase to reproduce the problem:

package javapns.test;

import org.json.JSONException;

import javapns.Push;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;
import javapns.devices.Device;
import javapns.devices.Devices;
import javapns.devices.exceptions.InvalidDeviceTokenFormatException;
import javapns.devices.implementations.basic.BasicDevice;
import javapns.notification.AppleNotificationServer;
import javapns.notification.AppleNotificationServerBasicImpl;
import javapns.notification.PushNotificationManager;
import javapns.notification.PushNotificationPayload;
import javapns.notification.PushedNotification;
import javapns.notification.PushedNotifications;
import javapns.notification.transmission.NotificationProgressListener;
import javapns.notification.transmission.NotificationThread;
import javapns.notification.transmission.NotificationThreads;

public class DuplicateTest extends TestFoundation implements 
NotificationProgressListener {

    /**
     * Execute this class from the command line to run tests.
     * 
     * @param args
     * @throws KeystoreException 
     * @throws JSONException 
     * @throws InvalidDeviceTokenFormatException 
     * @throws InterruptedException 
     */
    public static void main(String[] args) throws Exception {

        /* Verify that the test is being invoked  */
        if (!verifyCorrectUsage(DuplicateTest.class, args, "keystore-path", "keystore-password", "token")) return;

        /* Initialize Log4j to print logs to console */
        configureBasicLogging();

        test(args); 
    }

    private PushNotificationManager notificationManager;
    private AppleNotificationServer server;
    private int counter = 0;
    private NotificationThread thread;

    private DuplicateTest(String keystore, String password) throws KeystoreException, CommunicationException {
        server = new AppleNotificationServerBasicImpl(keystore, password, false);
        notificationManager = new PushNotificationManager();
        notificationManager.initializeConnection(server);

        thread = (NotificationThread) Push.queue(keystore, password, false, 1);
        thread.start();
    }

    private static void test(String[] args) throws KeystoreException, JSONException, InterruptedException, InvalidDeviceTokenFormatException {
        try {
            DuplicateTest test = new DuplicateTest(args[0], args[1]);

            test.sendExceptionNotification();
            Thread.sleep(1000);

            for (int i = 0; i < 2; i++) {
                test.sendNotification(args[2]);
            }

            Thread.sleep(1000);

            test.sendInvalidNotification();
            Thread.sleep(1000);

            for (int i = 0; i < 2; i++) {
                test.sendNotification(args[2]);
            }

            Thread.sleep(1000);

            test.restartConnection();

        } catch (Exception e) {
            System.out.println("   [ERROR]: Exception " + e);
        }

    }

    public void restartConnection() {
        try {
            thread.getPushedNotifications(true);
            //notificationManager.restartConnection(server);
        } catch (Exception e) {
            System.out.println("   [ERROR]: Exception " + e);
        }
    }

    //
    public void sendNotification(String token) throws JSONException, InvalidDeviceTokenFormatException, CommunicationException {
        int messageId = counter++;

        PushNotificationPayload payload = PushNotificationPayload.complex();
        System.out.println("   [SEND]: Notification Nr: " + messageId);
        payload.addAlert("Notification Nr: " +  messageId);
        Device device = new BasicDevice(token);

        thread.add(payload, device);

        //notificationManager.sendNotification(device, payload, false, messageId);
    }

    //6daca462dc30e6621b3e2886e176d6fa7f641e04741961a510a906b7dd51ae7b
    public void sendInvalidNotification() throws JSONException, InvalidDeviceTokenFormatException, CommunicationException {
        int messageId = counter++;
        PushNotificationPayload payload = PushNotificationPayload.complex();
        System.out.println("   [SEND]: Invalid Notification ");
        payload.addAlert("Invalid Notification: " + messageId);

        Device device = new BasicDevice("123456789012345678901234567890123456789012345678901234567" + (1000000));
        thread.add(payload, device);

        //notificationManager.sendNotification(device, payload, false, messageId);
    }

    public void sendExceptionNotification() throws JSONException, InvalidDeviceTokenFormatException, CommunicationException {
        int messageId = counter++;
        PushNotificationPayload payload = PushNotificationPayload.complex();
        System.out.println("   [SEND]: Exception Notification ");
        payload.addAlert("Exception Notification: " + messageId);

        Device device = new BasicDevice("123456789012345678901234567890123456789012345678901234567XXXXXXXX", false);
        thread.add(payload, device);

        //notificationManager.sendNotification(device, payload, false, messageId);
    }

    public void readStatus() {

    }

    public void eventThreadStarted(NotificationThread notificationThread) {
        System.out.println("   [EVENT]: thread #" + notificationThread.getThreadNumber() + " started");
    }

    public void eventThreadFinished(NotificationThread thread) {
        System.out.println("   [EVENT]: thread #" + thread.getThreadNumber() + " finished: pushed messages #" + thread.getFirstMessageIdentifier() + " to " + thread.getLastMessageIdentifier());
    }

    public void eventConnectionRestarted(NotificationThread thread) {
        System.out.println("   [EVENT]: connection restarted in thread #" + thread.getThreadNumber());
    }

    public void eventAllThreadsStarted(NotificationThreads notificationThreads) {
        System.out.println("   [EVENT]: all threads started: " + notificationThreads.getThreads().size());
    }

    public void eventAllThreadsFinished(NotificationThreads notificationThreads) {
        System.out.println("   [EVENT]: all threads finished: " + notificationThreads.getThreads().size());
    }

    public void eventCriticalException(NotificationThread notificationThread, Exception exception) {
        System.out.println("   [EVENT]: critical exception occurred: " + exception);
    }

}

Original comment by S.Yasar...@gmail.com on 25 Mar 2014 at 9:46

GoogleCodeExporter commented 8 years ago
Hello guys, 

I spotted a lot of duplicated messages received through APN yesterday(through 
our direct observation and customer feedback). We're using javapns 2.2 to send 
push messages. And I haven't touched our code or service for months.
Do you have any insight on what might be going on?

Thanks for any input.
Daolong Wang

Original comment by ahlon...@gmail.com on 1 Apr 2014 at 4:07

GoogleCodeExporter commented 8 years ago
Hi, here we are experiencing the resend as well. We have a bulk of 
notifications, several has invalid token, as result the devices with the valid 
token get several duplication. 

I understand that in a push were an error occurred there the following devices 
will not be reached. 
As such there is a need for the resend, I would prefer of course that only the 
following in the list will be sent, but if this not possible I would like the 
option to disable the resend.

Is there a way to configure the javapns to disable resend??

Original comment by kohen.sh...@gmail.com on 25 Jun 2014 at 12:01

GoogleCodeExporter commented 8 years ago
S.Yasar...@gmail.com is correct.
I tried his code and it is indeed sending duplicate notifications.

We need to change to code to include the fact that the successive notifications 
need not be resent in case the notification transmission 
(notification.isTransmissionCompleted()) has been unsuccessful.Because 
notifications succeeding such a notification shall be properly processed by 
APNS in case they have been successfully transmitted. 

Original comment by ram...@limeroad.com on 10 Jul 2014 at 1:21

GoogleCodeExporter commented 8 years ago
See issue #187

Original comment by sype...@gmail.com on 30 Sep 2014 at 3:27