Solved

Java RMI problem.  Connection Reset.

Posted on 2007-03-31
8
1,347 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: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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
github account with ecipse 1 50
egit plugin on eclipse 8 67
ejb on wildfly 5 20
Is Applet the way to go for my drag and drop system? 8 18
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

825 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