Skip to content
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

Apple Dropping Connection #14

Open
mikeytrw opened this issue Sep 22, 2010 · 8 comments
Open

Apple Dropping Connection #14

mikeytrw opened this issue Sep 22, 2010 · 8 comments

Comments

@mikeytrw
Copy link

We should look at tracking if/when a connection is severed by Apple's server.

If it after a specific message it may be an invalid token (debug send to production gateway or vice versa)
If it's unable to connect initially then it's likely the PEM file is screwed.

@jawj
Copy link
Contributor

jawj commented Sep 24, 2010

And/or it might be nice to upgrade to using Apple's new, enhanced protocol, which returns error codes in situations like this.

@mikeytrw
Copy link
Author

yes. I think that is esential

@mikeytrw
Copy link
Author

Right, I'm in no way experienced enough with Python to take the lead on the new struct packing format for new notification types. However I'm interested to know people's thoughts on implementation of the alert identifier.

I suggest the following:

Adding an 'identifier' param to the notify method that takes an identifier or array of identifiers that correspond to the array of tokens/alerts. On error the server returns an array of identifiers and array of corresponding error codes.

@samuraisam
Copy link
Owner

If you guys would like to test... I just pushed a branch called 'disconnection-log' which, when sending a message that doesn't complete, will add some data to APNSService.log which is retrievable via log you enable it by passing log_disconnections=True to provision or calling the new config method and setting 'log_disconnections' to True. Check out the docs:

http://github.com/samuraisam/pyapns/tree/disconnection-log

I will look into upgrading to use the newer protocol (I was unaware one had been released).

@n8gray
Copy link

n8gray commented Oct 28, 2010

I haven't tested the disconnection-log branch, but I like the idea a lot. The newer protocol is a simple extension of the old one and should make it much easier to identify the reason for failures.

@samuraisam
Copy link
Owner

The newer protocol looks easy enough to implement and may help with the reliability of disconnection-log. Currently it doesn't work great, given the asynchronous nature of twisted servers, it is tough to tell exactly which message and token it had failed on.

@samuraisam
Copy link
Owner

So @n8gray I have implemented the enhanced protocol (the easy part) and now disconnection log can tell exactly which token it had failed on. However, in production environments it is impossible to tell which message were /not/ sent due to a disconnection.

The problem is, these subsequent messages have already gone out over the wire, and Apple disconnects while those packets are in transmission. Apple offers NO acknowledgement of sent messages, so it is impossible to recover those that were not sent.

@ssutch
Copy link
Contributor

ssutch commented Feb 23, 2012

I have an idea with how to deal with this. The new protocol does not really give you any benefit when considering the disconnections. Any message that are already on the wire are lost.

The solution seems obvious to me now. To ensure that message are not lost due to disconnections:

  • maintain a pool of connections to apple's gateway
    • for each message send operation, check the connection out from the pool, removing it from general availability
    • if there are no available connections start a new one up to a certain threshold
    • after the time has passed without a disconnection, recycle the connection back to the pool
    • if a disconnection occurs expire the connection and log the offending token
  • your application periodically reads from a log of offending tokens or app ids.
    • this will be stored in memory so the frequency of reads should be some function of the total notifications sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants