yarj / javapns

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

Socket Reset, no error response or response packet #95

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.This is my code:

List<PushedNotification> notifications = Push.alert(message, certLocation, 
certPassword, isProduction, deviceIds);

        for (PushedNotification notification : notifications) {
            if (notification.isSuccessful()) {
                    /* Apple accepted the notification and should deliver it */  
                    System.out.println("Push notification sent successfully to: " +
                                                    notification.getDevice().getToken());

                    /* Still need to query the Feedback Service regularly */  
            } else {
                    String invalidToken = notification.getDevice().getToken();
                    /* Add code here to remove invalidToken from your database */  
                    removeToken(invalidToken);
                    /* Find out more about what the problem was */  
                    Exception theProblem = notification.getException();
                    ResponsePacket packet = notification.getResponse();

                    if(packet != null) {
                        System.out.println("packet.getMessage() = " + packet.getMessage());
                        System.out.println("packet.getStatus() = " + packet.getStatus());
                    }
                    theProblem.printStackTrace();

                    ResponsePacket theErrorResponse = notification.getResponse();
                    if (theErrorResponse != null) {
                            System.out.println(theErrorResponse.getMessage());
                    }
            }
        }

2. Try to send alert

What is the expected output? What do you see instead:

The notification is not sent, instead I get this stacktrace:

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:632)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
    at java.io.OutputStream.write(OutputStream.java:58)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:404)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:352)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:322)
    at javapns.Push.sendPayload(Push.java:176)
    at javapns.Push.alert(Push.java:47)
    at com.omeda.mobile.APNSCommunicator.sendAPNSNotification(APNSCommunicator.java:101)
    at com.omeda.mobile.APNSCommunicator.main(APNSCommunicator.java:72)

The ResponsePacket object is null as well.

I am using JavaPNS_2.1.1.jar

The thing is, this works outside my companys network. When I connect to my 
company's network over VPN or when sending notifications from our servers, it 
errors as described above. We are having a hard time figuring out whats going 
on.

It isn't clear whether the connection is being closed by Apple or by some 
process in our network that we are unaware of.

Can you point me in a direction or tell me what I might do to resolve this ?

I have a wireshark sniff available as well, if you would like to see that, I 
can email it.

I can be reached at amathias@omeda.com.

Original issue reported on code.google.com by aaron...@gmail.com on 10 Dec 2011 at 7:11

GoogleCodeExporter commented 8 years ago
Also, 'isProduction' is false, we are not using production destination.

Original comment by aaron...@gmail.com on 10 Dec 2011 at 7:20

GoogleCodeExporter commented 8 years ago
How many device ids are there in your list?

And could you provide the full log output for your attempt?  (or at least the 
last 50 lines preceding the exception)

Thank you!

Original comment by sype...@gmail.com on 10 Dec 2011 at 7:57

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
There is 1 deviceId in my list.

You can see above in my code I do the following:

Exception theProblem = notification.getException();
...
theProblem.printStackTrace();

The stack trace only yields:

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:632)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
    at java.io.OutputStream.write(OutputStream.java:58)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:404)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:352)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:322)
    at javapns.Push.sendPayload(Push.java:176)
    at javapns.Push.alert(Push.java:47)
    at com.omeda.mobile.APNSCommunicator.sendAPNSNotification(APNSCommunicator.java:101)
    at com.omeda.mobile.APNSCommunicator.main(APNSCommunicator.java:72)

Its really wierd, because like I said outside my companys network things work 
fine, but inside the network it errors out. Who/What would trigger a socket 
connection to close abruptly ? Again, the 3 way handshake seems to look okay 
(from what I am told) and I have wireshark sniffs available as well.

Original comment by aaron...@gmail.com on 10 Dec 2011 at 10:39

GoogleCodeExporter commented 8 years ago
I would like to see the log output from the library, not just the exception.  
The exception tells just part of the story, so the full log can be quite useful 
(because for now I can't tell what's wrong..).  Thanks!

Original comment by sype...@gmail.com on 10 Dec 2011 at 11:33

GoogleCodeExporter commented 8 years ago
Where can I find these logs ?

Original comment by aaron...@gmail.com on 10 Dec 2011 at 11:48

GoogleCodeExporter commented 8 years ago
Please see the Troubleshooting wiki page on this site.

Original comment by sype...@gmail.com on 10 Dec 2011 at 11:49

GoogleCodeExporter commented 8 years ago
Please find attached, thanks so much, anything else I can get you please let me 
know. I will make myself available.

Original comment by aaron...@gmail.com on 11 Dec 2011 at 12:05

Attachments:

GoogleCodeExporter commented 8 years ago
Would you like me to send you the logs for a successful submission as well 
(Outside my companys network)?

Original comment by aaron...@gmail.com on 11 Dec 2011 at 12:15

GoogleCodeExporter commented 8 years ago
From what I see in the log, JavaPNS does try to recover from the 
"java.net.SocketException: Connection reset, unexpected_message" error twice by 
trying again and again to reconnect and stream the message to the Apple server. 
 Unfortunately, the same "unexpected_message" SSL error occurs at every 
attempt, and JavaPNS eventually throws the exception because it reached the 
maximum number of attempts configured.

I really can't help you any further, as it seems to be a problem involving your 
network or security environment which breaks the comlink for some reason.  
Could there be a proxy on your company's network which somehow intercepts SSL 
connections and maybe doesn't like the trust strategy used between the library 
and APNS?  The fact that the library works outside of your network seems to be 
hinting toward that posibility also.

Original comment by sype...@gmail.com on 11 Dec 2011 at 12:17

GoogleCodeExporter commented 8 years ago
Thanks!

I sort of thought the same thing, but often times its easy to say "Hey Systems 
this is a firewall issue..", but if they can't fix it, then it leaves everyone 
in no-mans land.

a couple questions:

I am really not familiar with SSL connections and sockets, etc. If you were me, 
is there any explicit information from the logs I sent you that I could give 
them to point them in the correct direction ?

What is this "enexpected_message" error for example, can I google 
"unexpected_message SSL socket error" and get results, or do you think this is 
something custom to my companys network ?

Is there anything you are seeing I can use to verify that this is DEFINITELY 
happening on my companys side, ie we are closing the connection prematurely not 
Apple?

If you were me what would you tell the systems department.. ?

Original comment by aaron...@gmail.com on 11 Dec 2011 at 12:26

GoogleCodeExporter commented 8 years ago
I'm no SSL expert, but the first thing I'd do is to provide your IT department 
with a copy of the SSL log for an attempt that works outside of the network, 
and one that does not work inside the network.  In order to make it easier for 
them to investigate the issue, I would probably exclude JavaPNS-specific log 
entries from the logs I'd provide them (leaving only the log output generated 
by Java's -Djavax.net.debug=all option.

If one attempt works outside of the network and one fails inside, they ought to 
investigate it and provide a solution (or at least an explanation)..

Original comment by sype...@gmail.com on 12 Dec 2011 at 3:56

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Since your code works outside of your company network (hinting at a company 
network issue), I would suggest we close this issue.  Do you agree?

Original comment by sype...@gmail.com on 13 Dec 2011 at 2:52

GoogleCodeExporter commented 8 years ago
Bumping this issue..   May we close it?

Original comment by sype...@gmail.com on 20 Dec 2011 at 3:43

GoogleCodeExporter commented 8 years ago
Yes it ended up being a firewall issue.

Original comment by aaron...@gmail.com on 20 Dec 2011 at 4:59

GoogleCodeExporter commented 8 years ago
Excellent, thank you!

Closing.

Original comment by sype...@gmail.com on 20 Dec 2011 at 5:54