--- old/src/java.rmi/share/classes/sun/rmi/transport/tcp/TCPChannel.java Wed May 10 21:21:02 2017 +++ new/src/java.rmi/share/classes/sun/rmi/transport/tcp/TCPChannel.java Wed May 10 21:21:01 2017 @@ -296,11 +296,15 @@ out.flush(); } } catch (IOException e) { - if (e instanceof RemoteException) + try { + conn.close(); + } catch (Exception ex) {} + if (e instanceof RemoteException) { throw (RemoteException) e; - else + } else { throw new ConnectIOException( "error during JRMP connection establishment", e); + } } } else { try {