--- old/src/java.rmi/share/classes/sun/rmi/transport/tcp/TCPChannel.java Wed May 10 20:10:25 2017 +++ new/src/java.rmi/share/classes/sun/rmi/transport/tcp/TCPChannel.java Wed May 10 20:10:24 2017 @@ -296,11 +296,19 @@ out.flush(); } } catch (IOException e) { - if (e instanceof RemoteException) + if (e instanceof RemoteException) { throw (RemoteException) e; - else + } else { + if (conn != null + && e instanceof java.net.SocketTimeoutException) + { + try { + conn.close(); + } catch (Exception ex) {} + } throw new ConnectIOException( "error during JRMP connection establishment", e); + } } } else { try {