Configuring java-apns reconnection policy

523 views
Skip to first unread message

Geoffrey Stafford

unread,
Dec 2, 2011, 5:21:22 PM12/2/11
to java-apn...@googlegroups.com
I'm attempting to use the java-apns library and am running into an issue with the connections.  I've verified my usage is not re-using the same connection when pushing connections.  It basically opens a new connection for each notification.  Here is my code for creating the service:

rc = Provided.valueOf("NEVER");

service = APNS.newService().asPool(1).withReconnectPolicy(rc).withCert(certPathBase+"APNSCertificates.p12", "password").withSandboxDestination().build();

Is this correct?  I can verify the connection remains open for 2 hours when not pushing notifications. However, when a new notification is pushed the existing connection is closed and a new connection openend.


It's entirely possible my implementation of the library is causing this, but right now it is difficult to verify.

    

Mahmood Ali

unread,
Dec 13, 2011, 8:44:42 PM12/13/11
to java-apn...@googlegroups.com
Greetings Geoffrey,

Thanks for reporting your findings. However, testing the re-usability
of connection is a bit tricky.

When a connection is not used for a long time (e.g. in my environment
around 30 minutes), the connection might go stale. It is possible
that one of the servers or one of the intermediate routers/switches
will close it to free up some resources. In such cases, the
application may not detect that the connection actually closed (not
even with `connection.isClosed()`) until something is actually written
to the wire.

In your test scenario, it is very probable that the connection was
actually closed sometime within the two hours, but only got detected
as closed after the two hours of inactivity, when a message was about
to be written on the wire.

Check out the following article for more details:
http://www.codeproject.com/Articles/37490/Detection-of-Half-Open-Dropped-TCP-IP-Socket-Conne
.

In any case, this shouldn't be an issue with Apple. If you are
reconnecting only if you go stale (or once every 30 minutes), you
should be fine. Apple just doesn't want you to reconnect tens of
times a second.

- Mahmood

Reply all
Reply to author
Forward
0 new messages