Solved

Java RMI problem.  Connection Reset.

Posted on 2007-03-31
8
1,442 Views
Last Modified: 2011-04-12
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
Comment
Question by:Gezna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18831240
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
 

Author Comment

by:Gezna
ID: 18831317
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
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 total points
ID: 18831328
>> 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:Gezna
ID: 18832882
>>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
 

Author Comment

by:Gezna
ID: 18833005
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
 

Author Comment

by:Gezna
ID: 18833063
Sorry, typo, I meant to say that the bug is that all method calls on a proxy HANG.
0
 

Author Comment

by:Gezna
ID: 18833168
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 18848114
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question