SSL socket blocks on close
I am using an ssl socket connection with a long lifespan. I'm using it to receive event information from a server.
My problem occurs when the client os's underlying network connection drops out and comes back. When it re-appears the application re-establishes the event socket connection, by first calling disconnect shown here:
protectedfinalvoid disconnect()throws IOException{
try{
output.flush();
}finally{
try{
output.close();
}finally{
output =null;
try{
input.close();
}finally{
input =null;
try{
socket.close();
}finally{
socket =null;
}
}
}
}
}
I'm noticing that when using SSL this code blocks on either input.close(); (the socket's input stream) or socket.close(); (if input.close() has been commented out).
"MyEventThread" daemon prio=10 tid=0x0818c400 nid=0x6c66 waitingfor monitor entry [0xacaba000..0xacabaf30]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:714)
- waiting to lock <0xae8e4738> (a java.lang.Object)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1368)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.closeInternal(SSLSocketImpl.java:1324)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.close(SSLSocketImpl.java:1218)
I'm not sure as to the correct approach here; if i need to make the application-level code aware of the specific case where the network is dropped and write an implementation that doesn't bother trying to close and just nullify everything or if a better option is to set socket-level options to try and adjust the ssl-socket's implementation behaviour.
Thanks.

