Code Monkey home page Code Monkey logo

Comments (34)

argon avatar argon commented on June 12, 2024

This is very strange. Are you able to compare the data generated by node-apn to that generated by the PHP code? I can't immediately think of a reason which might cause this.

from node-apn.

kyannai avatar kyannai commented on June 12, 2024

Ah, i guess I found the reason.

When I try to send multiple push notifications and if one of the hextoken is invalid, the following will not get through as well.

For example,

var strBadHextoken = 'xxx';
var strGoodHextoken = 'yyy';

var myDevice1 = new apns.Device(strBadHextoken);
var myDevice2 = new apns.Device(strGoodHextoken);

var note = new apns.Notification();
note.badge = 1;
note.sound = "ping.aiff";
note.alert = "You have a new message";
note.payload = {'messageFrom': 'Tester'};

note.device = myDevice1;
apnsConnection.sendNotification(note);
note.device = myDevice2;
apnsConnection.sendNotification(note);

In this case, myDevice2 will not receive any push notification.
Any idea how to solve this?

Thank you!

from node-apn.

stadja avatar stadja commented on June 12, 2024

I have exactly the same issue :/

from node-apn.

argon avatar argon commented on June 12, 2024

I am currently rewriting the connection handling code. I hope to have something available at the weekend which should fix this problem.

from node-apn.

stadja avatar stadja commented on June 12, 2024

Nice !
I'll be testing whenever you want... for more than 26000 pushes :)

from node-apn.

kyannai avatar kyannai commented on June 12, 2024

Thank you very much :)

from node-apn.

argon avatar argon commented on June 12, 2024

The problem is that you are reusing a notification object:

note.device = myDevice1;
apnsConnection.sendNotification(note);
note.device = myDevice2;
apnsConnection.sendNotification(note);

Try creating a notification object for each device. I'm still trying to decide on a good solution for sending the same notification to multiple devices

from node-apn.

argon avatar argon commented on June 12, 2024

In v1.2.0 notifications will have a .clone(device) method to clone a notification to send to multiple devices.

from node-apn.

argon avatar argon commented on June 12, 2024
apnsConnection.sendNotification(note.clone(myDevice1));
apnsConnection.sendNotification(note.clone(myDevice2));

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Hi Argon, first, thanks a lot for this great node module.

Sadly I'm having the same issue. I'm sending a new notification to each of 50 devices. But as soon as there is a invalid device, the notifications won't get delivered. In 50% of my tests I will get this error with node crashing:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: write EPIPE
    at errnoException (net.js:646:11)
    at Object.afterWrite [as oncomplete] (net.js:480:18)

from node-apn.

argon avatar argon commented on June 12, 2024

Can you confirm which version of the code you're running?

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Sorry, I'm running the latest version: 1.2.0 but had the same issue with 1.1.

If I limit the devices to a smaller number, e.g. 5, and having one with a wrong token, everything seems to work.

from node-apn.

argon avatar argon commented on June 12, 2024

Are you able to consistently reproduce this problem? I have some ideas about how to handle this, would you be willing to try my changes?

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Yes, I can reproduce this every time. That would be great!

from node-apn.

argon avatar argon commented on June 12, 2024

Could you run your application with NODE_DEBUG=tls,net node app.js and post the result to allow me to pinpoint the problem further?

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Thanks a lot for looking into this. You can find the log here: http://pastebin.com/4r3sLUMY

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

here you can find my node source: http://pastebin.com/xpBksrnd

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

There is another problem: If I manually remove all invalid tokens and send the push message to all (about 2300) devices I don't get any errors but the push message is never received by my device which is one of the last in the list.

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

In connection.js: If I replace "this.socket.destroySoon()" with "this.socket.destroy()" I don't get any EPIPE errors and node is not killed but the push message still won't get delivered to the following devices.

from node-apn.

argon avatar argon commented on June 12, 2024

could you pull the copy of the module on the 'develop' branch, npm install debug and run DEBUG=apn NODE_DEBUG=tls,net node app.js and post your results. I have changed destroySoon to destroy and made a few small changes which may fix your problem in addition to adding logging.

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

No more node kills but still no push messages after a device with a invalid token: http://pastebin.com/nZhViGNa

I think that the queue is not processed again after an error occurs.

Isn't this strange?

Fri, 22 Jun 2012 22:31:11 GMT apn Restarting connection
NET: destroy
NET: close
Fri, 22 Jun 2012 22:31:11 GMT apn Sending notification
Fri, 22 Jun 2012 22:31:11 GMT apn Sending notification

from node-apn.

argon avatar argon commented on June 12, 2024

Sorry to take up so much of your time, I think I found the problem, I made too many changes! Can you try the latest on develop and see if it helps. I really appreciate it.

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

I really appreciate all of your work. So don't thank me. I have to thank you :)

But I'm sorry to tell you that the latest update don't fix the problem. Still no push message on the device :(

Current debug log: http://pastebin.com/SyyWGkeW

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

What I don't get is why it stops at the second try:

 apn Sending notification +0ms
  apn Sending notification +0ms
  apn Sending notification +0ms
  apn Notification 0 caused an error: 8 +111ms
  apn Raising error: 8 +1ms { encoding: 'utf8',
  payload: { aps: { badge: 1 } },
  expiry: 0,
  identifier: 0,
  alert: undefined,
  badge: 1,
  sound: undefined,
  newsstandAvailable: undefined,
  device: { token:  },
  _uid: 0 }


APNS ERROR:


8
{ encoding: 'utf8',
  payload: { aps: { badge: 1 } },
  expiry: 0,
  identifier: 0,
  alert: undefined,
  badge: 1,
  sound: undefined,
  newsstandAvailable: undefined,
  device: { token:  },
  _uid: 0 }
  apn Buffering 9 notifications +1ms
  apn Destroying connection +0ms
  apn Restarting connection +4ms
  apn Notification queue has 9 items, resending the first +0ms
  apn Initialising connection +0ms
NET: destroy
NET: close
NET: connect: find host gateway.push.apple.com
NET: afterConnect
NET: Drain the connect queue
  apn Connection established +508ms
  apn Sending notification +1ms

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

The first device (notification) on the second round gets the push message successfully but it won't continue to process the queue.

from node-apn.

argon avatar argon commented on June 12, 2024

Can you replace the socketDrained method in connection.js with the following and try again, when it finishes sending one notification it is supposed to process the next but it doesn't seem to be doing this. Need to establish the point it is getting to

Connection.prototype.socketDrained = function() {
    debug("Socket drained");
    if (this.socket && (this.socket.socket.bufferSize != 0 || !this.socket.writable)) {
        return;
    }
    debug("Socket writeable");
    if (this.notificationBuffer.length > 0) {
        debug("Sending notification from buffer");
        this.sendNotification(this.notificationBuffer.shift());
    }
};

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Still no change: http://pastebin.com/Z5k2fENh

from node-apn.

argon avatar argon commented on June 12, 2024

I think I have found the problem. Just making sure I code the change correctly.

from node-apn.

argon avatar argon commented on June 12, 2024

I have pushed a (hopeful) fix to the develop branch. Please let me know how things go.

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Thanks so much. Works like a charm, now :)

from node-apn.

d-a-n avatar d-a-n commented on June 12, 2024

Can you leave the debug logs in code? I find it really helpful to see whats going on.

from node-apn.

argon avatar argon commented on June 12, 2024

Great, I'll merge this into the next release. I may change the debugging a little but it was always my intention to introduce them to the next release.

from node-apn.

tilo avatar tilo commented on June 12, 2024

@argon could you add a comment what the problem was and how you fixed this?

from node-apn.

argon avatar argon commented on June 12, 2024

I have made many changes since this issue to address reliability, including a change currently on "develop" which should also tackle the EPIPE problem at the source. If you're having a specific problem which you think is related to this could you please open a new issue so I can track it properly.

from node-apn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.