Solved

Java RMI problem.  Connection Reset.

Posted on 2007-03-31
8
1,397 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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