lblazecki/nodejs-apns-secure — pull request #1 by jblebrun (2013-04-25 01:36:26+00:00)
Title: Fix potential double-callback situation

In node v.0.10, ECONNRESET errors are reported more often (see
https://github.com/joyent/node/pull/4775)

As a result, sometimes this sender can get into a state where it ends up
sending the success callback twice. The test case is sending one
notification with an invalid notification ID (in addition to the
sentinel with the invalid ID that is added internally).

*The notifications are sent
*An error data response is returned
**resendThroughApns is called for the remaining notification
*Sometimes, the connection is ALSO closed with ECONNRESET!
**reconnect is scheduled for 1 second later

When the resend occurs quickly (<1 s) it sends the callback. However,
the final notification is left in the array, so we reconnect fires, it
sends the remaining stuff 1 more time.

To get around this, reconnect timeouts are cleared before sending any
callbacks.