Solved

Java RMI problem.  Connection Reset.

Posted on 2007-03-31
8
1,303 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
  • 5
  • 3
8 Comments
 
LVL 30

Expert Comment

by:mayankeagle
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:
mayankeagle 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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:mayankeagle
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now