title: Java RMI TCPEndpoint new socket timeout
body: <p>I have an application with a simple client and server communicating through RMI.</p>
  
  <p>I'm playing around to see how the client behaves when I kill the server.</p>
  
  <p>The client gets stuck on creating a new socket. You can see the exception bellow:</p>
  
  <pre><code>Caused by: java.rmi.ConnectException: Connection refused to host:     172.17.2.100; nested exception is: 
  java.net.ConnectException: Connection timed out
                    at     sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
                    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
                    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
                    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
                    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
                    ... 18 more.
  
  Caused by: java.net.ConnectException: Connection timed out
                    at java.net.PlainSocketImpl.socketConnect(Native Method)
                    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
                    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
                    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
                    at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
                    ... 30 more.
  </code></pre>
  
  <p>At first I thought this had something to do with the sockets created by the RMIClientSocketFactory passed when creating the registry, but as you can see from the exception it's when the TCPEndpoint tries to create a new socket.</p>
  
  <p>Since TCPEndpoint explicitly creates a new socket without using a timeout, I really don't see how to overcome this.</p>
  
  <p>Any ideas?</p>