• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1668
  • Last Modified:

Java RMI problem. Connection Reset.

java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
      java.net.SocketException: Connection reset
      at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
      at sun.rmi.server.UnicastRef.invoke(Unknown Source)
      at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
      at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
      at $Proxy0.gameOverEvent(Unknown Source)
      at titan.rmi.TitanPlayer_RMIClient.gameOverEvent(TitanPlayer_RMIClient.java:112)
      at com.biotools.poker.E.I.gameOverEvent(Unknown Source)
      at com.biotools.poker.Q.K.r(Unknown Source)
      at com.biotools.poker.Q.K.L(Unknown Source)
      at com.biotools.poker.Q.K.V(Unknown Source)
      at com.biotools.poker.PokerApp.?(Unknown Source)
      at com.biotools.poker.PokerApp$6.run(Unknown Source)
      at com.biotools.poker.PokerApp$5.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(Unknown Source)
      at java.io.BufferedInputStream.fill(Unknown Source)
      at java.io.BufferedInputStream.read(Unknown Source)
      at java.io.DataInputStream.readByte(Unknown Source)
      ... 14 more


I get the above after an hour or longer of running my program.  The client and server are on the same machine (localhost).  Therefore there is no network issue.
0
Gezna
Asked:
Gezna
  • 5
  • 3
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
Did the server encounter an exception and crash too?

Probably the server is configured to accept only a specific number of connections (50 on ServerSocket by default), and could not accept more.
0
 
GeznaAuthor Commented:
Connection was reset, not refused.  So probably it is not the case that the server refused to accept more.

The client is only asking for one and only one proxy object and then proceeds to use the proxy for many method calls.  It isn't the case that the client is asking for many proxies in succession.  It is my understanding of RMI that this means only one socket connection is open.  Correct me if I'm wrong, please.

The issue has been reproduced on two different machines.  The server appears to be normal in that nothing is printed to the console.  I have the RMI service running in verbose mode.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Connection was reset, not refused.  

Correct, it could be reset due to that as well.

>> It isn't the case that the client is asking for many proxies in succession.

That doesn't matter. The proxy is just a dummy. The connection is opened and closed for every method call made.

>> It is my understanding of RMI that this means only one socket connection is open.  Correct me if I'm wrong, please.

I'm afraid so.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GeznaAuthor Commented:
>>That doesn't matter. The proxy is just a dummy. The connection is opened and closed for every method call made.

If so that is a big clue.  I know from other work that I've done that OS's do have limits to how fast you can open new socket connections.  This indeed could be what is happening.

I have run versions of this program that run a little less method calls per second without problems.  I will increase the number of new socket connections allowed (I'm running winxp sp2) and see if that helps.  The other thing I can try is slow down this program and see if that helps too.
0
 
GeznaAuthor Commented:
Here's another clue:

I can reproduce the problem when I run this JUnit test.  It simply calls a method on the proxy over and over again as quickly as it can.

ITitanPlayer it=null;
      String host = "localhost";
      
      @Before
      public void setUp() throws Exception {
            getProxy();
      }
      
      
      
      
      @Test
      public void testInit(){
            try {
                  Preferences p = new Preferences();
                  it.init(p);
                  System.out.println("Done init.");
            } catch (RemoteException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
            
      }
      @Test
      public void loadTest(){
            int N=1000000;
            for(int i=0;i<N;i++){
                  testInit();
            }
      }

      @After
      public void tearDown() throws Exception {
      }
      
      private void getProxy() {
            // Get the proxy from the RMI server
            try {
                  System.setSecurityManager(new RMISecurityManager());
                  Registry registry = LocateRegistry.getRegistry(host);
                  it = (ITitanPlayer) registry.lookup("PokerBotServer");
                  if (it != null)
                        System.err.println("Seems to be successful");
                  else
                        System.err.println("Didn't get proxy!");
            } catch (Exception e) {
                  System.err.println("Exception while trying to connect. ");
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

      }

The bug is that all method calls on a proxy hand.  I can create new proxies, but I cannot call methods on them.  The call begins, but it never returns.
0
 
GeznaAuthor Commented:
Sorry, typo, I meant to say that the bug is that all method calls on a proxy HANG.
0
 
GeznaAuthor Commented:
Think I figured it out.  It appears to be a deadlock having to do with a JFrame I use for displaying debugging info on the server side.

@Test
      public void loadTest(){
            int N=500000;
            long pause=10L;
            try {
                  for(int i=0;i<N;i++){
                        Thread.currentThread().sleep(pause);
                        if(pause>0&&i%100==0)pause--;
                        System.out.println("N = "+i+" pause = "+pause);
                        testInit();
                  }
            } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
      }

The above test reproduces my bug between 500 and 1500 iterations when the JFrame is displaying messges.

When I turn off the JFrame, the test doesn't fail.

A deadlock would explain why there wasn't a stack trace.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Sorry for the delay - I am occupied with work. I will get back to you on this. Or have you opened another question?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now