0 Replies Latest reply: Jun 9, 2011 11:18 PM by 867978 RSS

    Client (Solaris) remote call hangs 225sec if Server (Window7) is down.

    867978
      We are noticing the RMI Client remote call from Solaris machine hang of exactly 225 seconds if RMI Server on Windows7 machine is shutdown. RMI Server is shutdown for valid reasons. The expectation is, Client would throw a RemoteException immediately for futher processing. The Client hang for 225 minutes is causing performance issues. This has been consistently reproduced across multiple machines with Client on Solaris and Server on Windows 7. There are no 225 sec wait issues if server is on Windows XP or Solaris.
      Usecase (java version "1.6.0_14")
      1. Start RMI Server on Windows 7 machine
      2. Start RMI Client on Solaris machine
      3. Wait till client connects to the server and makes some remote call every 1sec.
      4. Shutdown RMI Server.
      5. Client waits 225 seconds before a time out error is thrown.

      Has anyone seen this problem? Any solutions to get around this?

      Code used to test this
      RmiTestServer.java
      public class RmiTestServer
      {
      public static void main(String args[])
      {
      try
      {
      java.rmi.registry.Registry zRegistry = null;

      try
      {
      zRegistry = java.rmi.registry.LocateRegistry.createRegistry ( 1099 );
      }
      catch ( Exception zEx )
      {
      zRegistry = java.rmi.registry.LocateRegistry.getRegistry ( 1099 );
      }

      if ( zRegistry != null )
      {
      System.out.println( "Binding RmiTestService..." );
      RmiTest c = new RmiTestImpl();
      zRegistry.rebind ( "RmiTestService", c );
      System.out.println( "Done Binding RmiTestService..." );
      }
      else
      {
      System.out.println( "Registry is null." );
      }
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }
      }

      RmiTest.java
      public interface RmiTest extends java.rmi.Remote
      {
      public void callHello() throws java.rmi.RemoteException;
      }
      RmiTestImpl.java
      public class RmiTestImpl extends java.rmi.server.UnicastRemoteObject
      implements RmiTest
      {
      public RmiTestImpl() throws java.rmi.RemoteException
      {
      super();
      }

      public void callHello() throws java.rmi.RemoteException
      {
      System.out.println ("Hello World!!!");
      }
      }

      RmiTestClient
      public class RmiTestClient
      {
      public static void main(String[] args)
      {
      System.out.println ("Connecting to: " + args[0] + " Port 1099" );
      long lTime = System.currentTimeMillis();
      try
      {
      RmiTest c = null;
      java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.getRegistry ( args[0], 1099 );

      if ( registry!=null )
      {
      System.out.println ("Start lookup... " );
      c = (RmiTest)registry.lookup ( "RmiTestService" );
      }

      System.out.println( "Lookup Done - " + (System.currentTimeMillis() - lTime)/1000 + "sec\n" );
      while( true )
      {
      lTime = System.currentTimeMillis();
      System.out.println( "Calling Server..." );
      c.callHello();
      System.out.println( "Done Calling Server - " + (System.currentTimeMillis() - lTime)/1000 + "sec\n" );
      lTime = System.currentTimeMillis();
      Thread.sleep(1000);
      }
      }
      catch (Exception e)
      {
      System.out.println( "Time for Exception - " + (System.currentTimeMillis() - lTime)/1000 + "sec\n" );
      e.printStackTrace();
      }
      }
      }

      Output

      Calling Server...
      Jun 9, 2011 10:59:19 PM sun.rmi.transport.tcp.TCPChannel newConnection
      FINE: main: reuse connection
      Jun 9, 2011 10:59:19 PM sun.rmi.transport.tcp.TCPChannel free
      FINE: main: reuse connection
      Done Calling Server - 0sec

      Calling Server...
      Jun 9, 2011 10:59:20 PM sun.rmi.transport.tcp.TCPChannel newConnection
      FINE: main: reuse connection
      Jun 9, 2011 10:59:20 PM sun.rmi.transport.tcp.TCPChannel free
      FINE: main: reuse connection
      Done Calling Server - 0sec

      Calling Server...
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.tcp.TCPConnection isDead --------------->RMI Server Shutdown
      FINER: main: exception:
      java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(SocketInputStream.java:168)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
      at sun.rmi.transport.tcp.TCPConnection.isDead(TCPConnection.java:174)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:173)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
      at RmiTestImpl_Stub.callHello(Unknown Source)
      at RmiTestClient.main(RmiTestClient.java:23)
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.tcp.TCPConnection isDead
      FINE: main: server ping failed
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.tcp.TCPChannel free
      FINE: main: close connection
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.tcp.TCPConnection close
      FINE: main: close connection
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.tcp.TCPChannel createConnection
      FINE: main: create connection
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.tcp.TCPEndpoint newSocket
      FINER: main: opening socket to [<IP Address>:65427]
      Jun 9, 2011 10:59:21 PM sun.rmi.transport.proxy.RMIMasterSocketFactory createSocket
      FINE: main: host: <IP Address>, port: 65427
      Jun 9, 2011 10:59:24 PM sun.rmi.transport.tcp.TCPChannel$1 run
      FINER: RMI Scheduler(0): wake up
      Jun 9, 2011 10:59:24 PM sun.rmi.transport.tcp.TCPChannel$1 run
      FINER: RMI Scheduler(0): wake up
      Jun 9, 2011 10:59:39 PM sun.rmi.transport.tcp.TCPChannel$1 run
      FINER: RMI Scheduler(0): wake up
      Jun 9, 2011 10:59:39 PM sun.rmi.transport.tcp.TCPChannel freeCachedConnections
      FINER: RMI Scheduler(0): connection timeout expired
      Jun 9, 2011 10:59:39 PM sun.rmi.transport.tcp.TCPConnection close
      FINE: RMI Scheduler(0): close connection
      Time for Exception - 224sec

      java.rmi.ConnectException: Connection refused to host: <IP Address>; nested exception is:
      java.net.ConnectException: Connection timed out
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
      at RmiTestImpl_Stub.callHello(Unknown Source)
      at RmiTestClient.main(RmiTestClient.java:23)
      Caused by: java.net.ConnectException: Connection timed out
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      at java.net.Socket.connect(Socket.java:529)
      at java.net.Socket.connect(Socket.java:478)
      at java.net.Socket.<init>(Socket.java:375)
      at java.net.Socket.<init>(Socket.java:189)
      at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
      at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
      ... 5 more