Archived

This forum has been archived. Please start a new discussion on GitHub.

Pb between C++ client and Java Server

Hello,


My server is in C++. It is on a Toshiba TX board (Ice can be ported onto a Toshiba TX board, which can be a good news for you !!)
On the board, Linux Montavista is installed.

My client is in Java on a Windows PC.

I tried "Minimal" example . It works perfectly.

But when I would like to improve the programms, I have some problems.

The server is running. I execute the client. All is all right. The execution is good.
The server is still running. But when I would like to execute the client an other time, the server goes down and I have this message :

server: ../../../include/IceUtil/Mutex.h:299: IceUtil::Mutex::~Mutex(): Assertion `rc == 0' failed.
Aborted

I tried to modify some parts of the server and the client, but I get always this message after a second try....

With Minimal example, I can execute as many time as I want the client, the server never goes down...

What can I do ?? :confused:

Thank you for your help !

Comments

  • Do you have a way to get a stack trace? That would help a lot toward finding the problem.

    Also, if you could post the complete code for client and server, we could have a look at what might be wrong.

    Cheers,

    Michi.
  • The client source :
    import Demo.*;
    import java.util.*;
    
    public class Client {
    
    	public static void main(String []args) {
    
    		Random random = new Random ();
    		Transmit trans;
    		
    		String s = null;
    		
    		int status = 0;
    		Ice.Communicator ic = null;
    		try {
    		 	ic = Ice.Util.initialize (args);
    			Ice.ObjectPrx base = ic.stringToProxy("hello:tcp -p 10000 -h 156.189.89.125");
    			Demo.HelloPrx hello = Demo.HelloPrxHelper.checkedCast(base);
    			if (hello == null) throw new Error("Invalid proxy");
    			
    			hello.sayHello("Hello !!");			
    
    			for (int i = 0; i < 3; i++)  {
    				int a = random.nextInt();
    				double d1 = random.nextDouble()*10000;
    				double d2 = random.nextDouble()*10000;
    				double d3 = random.nextDouble()*10000;
    
    				trans = hello.setClass(a, d1, d2, d3);
    				System.out.println("a : " + trans.a);
    				System.out.println("arr0 : " + trans.arr[0]);
    				System.out.println("arr1 : " + trans.arr[1]);
    				System.out.println("arr2 : " + trans.arr[2]);
    				hello.sendClass(trans); //send to the server
    			}
    			
    		} catch (Ice.LocalException e) {
    			e.printStackTrace();
    			status = 1;
    		} catch (Exception e) {
    			System.out.println(e.getMessage());
    			status = 1;
    		}
    		if(ic != null) {
    		  try {
    		        ic.destroy();
    		  } catch (Exception e) {
    		        System.out.println(e.getMessage());
    			  status = 1;
    		   }
    		}
    	System.exit(status);
    	}  //main
    } // Client
    

    The server :
    #include <HelloI.h>
    #include <Ice/Ice.h>
    
    using namespace std;
    
    
    int
    main(int argc, char* argv[])
    {
        int status = EXIT_SUCCESS;
        Ice::CommunicatorPtr communicator;
        cout << "Server ready ..." << endl;
    
        try
        {
    	communicator = Ice::initialize(argc, argv);
    	Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Hello", "tcp -p 10000");
    	adapter->add(new HelloI, Ice::stringToIdentity("hello"));
    	adapter->activate();
    	communicator->waitForShutdown();
        }
        catch(const Ice::Exception& ex)
        {
    	cerr << ex << endl;
    	status = EXIT_FAILURE;
        }
    
        if(communicator)
        {
    	try
    	{
    	    communicator->destroy();
    	}
    	catch(const Ice::Exception& ex)
    	{
    	    cerr << ex << endl;
    	    status = EXIT_FAILURE;
    	}
        }
    
        return status;
    }
    


    HelloI.cpp
    #include <HelloI.h>
    #include <Ice/Ice.h>
    
    using namespace std;
    
    void HelloI::sayHello(const string& s, const Ice::Current&) 
    {
        cout << s << endl;
    }
    
    Demo::TransmitPtr HelloI::setClass(int a, double d1, double d2, double d3, const Ice::Current&) {
      array arr (3);
      arr[0] = d1;
      arr[1] = d2;
      arr[2] = d3;
      TransmitPtr trans = new Transmit(a,arr);
      
      cout << "in setClass..." << endl;
      cout << "a : "<< trans->a << endl; 
      cout << "arr 0 : "<< trans->arr[0] << endl; 
      cout << "arr 1 : "<< trans->arr[1] << endl; 
      cout << "arr 2 : "<< trans->arr[2] << endl; 
      
      return trans;
    }
    
    void HelloI::sendClass(const TransmitPtr& trans, const Ice::Current&) {
      array arr (3);
      int a = trans->a;
      for (int i = 0; i < 3; i++) arr[i] = trans->arr[i];
      TransmitPtr trans_new = new Transmit(a,arr);
    
      cout << "in sendClass..." << endl;
      cout << "a : "<< trans_new->a << endl; 
      cout << "arr 0 : "<< trans_new->arr[0] << endl; 
      cout << "arr 1 : "<< trans_new->arr[1] << endl; 
      cout << "arr 2 : "<< trans_new->arr[2] << endl; 
    
    }
    

    HelloI.h
    #ifndef HELLO_I_H
    #define HELLO_I_H
    
    #include <Hello.h>
    
    using namespace std;
    using namespace Demo;
    
    class HelloI : public Demo::Hello
    {
    public:
    
        void sayHello(const string& s, const Ice::Current&);
        Demo::TransmitPtr setClass(int a, double d1, double d2, double d3, const Ice::Current&);
        void sendClass(const TransmitPtr& trans, const Ice::Current&);
    };
    
    #endif
    

    Hello.ice
    #ifndef HELLO_ICE
    #define HELLO_ICE
    
    module Demo
    {
    sequence<double> array;
    
    class Transmit {
          int a;
          array arr;
    }
    
    interface Hello
    {
       void sayHello(string s);
       Transmit  setClass(int a, double d1, double d2, double d3);
       void sendClass(Transmit trams);
    };
    
    };
    
    #endif
    
    

    Could you tell me how to get a stack trace ?

    Thank you very much
  • This is the stack trace :

    before 1st try :

    #0 0x00626978 in __pthread_sigsuspend (set=0x7fff78a8)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    #1 0x00626690 in __pthread_wait_for_restart_signal (self=0x10007ca0)
    at pthread.c:1145
    #2 0x00621144 in __pthread_cond_wait (cond=0x100cb70c, mutex=0x100cb718)
    at restart.h:34
    #3 0x00507e6c in waitImpl<IceUtil::RecMutex> (this=0x100cb70c,
    mutex=@0x100cb718) at Cond.h:203
    #4 0x00506468 in IceUtil::Monitor<IceUtil::RecMutex>::wait() const (
    this=0x100cb70c) at Monitor.h:152
    #5 0x00503d8c in IceInternal::ObjectAdapterFactory::waitForShutdown() (
    this=0x100cb6e8) at ObjectAdapterFactory.cpp:66
    #6 0x005d9ad4 in Ice::CommunicatorI::waitForShutdown() (this=0x100cae20)
    at CommunicatorI.cpp:119
    #7 0x0041cb70 in main (argc=1, argv=0x7fff7da4) at Server.cpp:29


    after 1st try :
    #0 0x00626978 in __pthread_sigsuspend (set=0x7fff78a8)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    #1 0x00626690 in __pthread_wait_for_restart_signal (self=0x10007ca0)
    at pthread.c:1145
    #2 0x00621144 in __pthread_cond_wait (cond=0x100cb70c, mutex=0x100cb718)
    at restart.h:34
    #3 0x00507e6c in waitImpl<IceUtil::RecMutex> (this=0x100cb70c,
    mutex=@0x100cb718) at Cond.h:203
    #4 0x00506468 in IceUtil::Monitor<IceUtil::RecMutex>::wait() const (
    this=0x100cb70c) at Monitor.h:152
    #5 0x00503d8c in IceInternal::ObjectAdapterFactory::waitForShutdown() (
    this=0x100cb6e8) at ObjectAdapterFactory.cpp:66
    #6 0x005d9ad4 in Ice::CommunicatorI::waitForShutdown() (this=0x100cae20)
    at CommunicatorI.cpp:119
    #7 0x0041cb70 in main (argc=1, argv=0x7fff7da4) at Server.cpp:29


    after 2nd try :

    #0 0x00626978 in __pthread_sigsuspend (set=0x7fff78a8)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    #1 0x00626690 in __pthread_wait_for_restart_signal (self=0x10007ca0)
    at pthread.c:1145
    #2 0x00621144 in __pthread_cond_wait (cond=0x100cb70c, mutex=0x100cb718)
    at restart.h:34
    #3 0x00507e6c in waitImpl<IceUtil::RecMutex> (this=0x100cb70c,
    mutex=@0x100cb718) at Cond.h:203
    #4 0x00506468 in IceUtil::Monitor<IceUtil::RecMutex>::wait() const (
    this=0x100cb70c) at Monitor.h:152
    #5 0x00503d8c in IceInternal::ObjectAdapterFactory::waitForShutdown() (
    this=0x100cb6e8) at ObjectAdapterFactory.cpp:66
    #6 0x005d9ad4 in Ice::CommunicatorI::waitForShutdown() (this=0x100cae20)
    at CommunicatorI.cpp:119
    #7 0x0041cb70 in main (argc=1, argv=0x7fff7da4) at Server.cpp:29


    I hope it can help you !!

    Thank you !
  • benoit
    benoit Rennes, France
    Bonjour Arnaud,

    I can't see anything wrong with your code and the stack traces aren't very helpful. What would really help is to see the stack trace of the assert. You should be able to get it by running the server under the debugger. When the server crashes, gdb should notify you that the program terminated and it should allow you to get the stack trace of the assert (using the "where" gdb command.)

    Alternatively, you could enable core files (by running "ulimit -c unlimited" in the shell where you run the server) and then open with gdb the server with this core file with "gdb ./server core.<pid>" (after the server crashed).

    Cheers,
    Benoit.
  • Bonjour Benoit,

    So, I tryed the method you told me but I think I should have done it not correctly.

    I start the server. I got his pid.
    After, I open the server using : gdb server core."PID". I got this :

    gdb server core.439
    GNU gdb 5.2.1
    Copyright 2002 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "mipsel-hardhat-linux"...
    /root/intent/home/arnaud/Ice-3.0.1-ok/demo/Ice/minimal/minimal2/core.439: No suc
    h file or directory.

    I run the client

    When the server crashes I type "where" and I have this :

    No stack.

    What is bad in what I do ?

    Thank you !
  • benoit
    benoit Rennes, France
    The file named core.<pid> is created only after the process abnormally terminated. Try something like the following instead:
      $ ulimit -c unlimited
      $ ./server
      <wait for server to assert>
      $ ls core.*
      $ gdb ./server core.<pid>
    

    If no core files is created, it's possible that core files don't work on your box. In this case, I would try to run the server under the debugger, something like the following for example:
      $ gdb ./server
      (gdb) run
      <wait for server to assert>
      (gdb) where
    

    Cheers,
    Benoit.
  • Merci !!

    I used the first method

    I got this :

    Program terminated with signal 6, Aborted.
    #0 0x006c1c04 in kill () at <stdin>:2
    2 <stdin>: No such file or directory.
    in <stdin>

    is it ok ?
  • benoit
    benoit Rennes, France
    No, I'm afraid this doesn't say much. Can you try the second method instead (run the server under debugger)?

    Benoit.
  • second method :

    Starting program: /root/intent/home/arnaud/Ice-3.0.1-ok/demo/Ice/minimal/minimal
    2/server
    Server ready ...

    Program received signal SIG32, Real-time event 32.
    0x00626978 in __pthread_sigsuspend (set=0x7fff7678)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    53 ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c: No such file or
    directory.
    in ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c
    Current language: auto; currently c
    (gdb) where
    #0 0x00626978 in __pthread_sigsuspend (set=0x7fff7678)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    #1 0x00626690 in __pthread_wait_for_restart_signal (self=0x10007ca0)
    at pthread.c:1145
    #2 0x006257e4 in __pthread_create_2_1 (thread=0x100cb940, attr=0x4,
    start_routine=0xffffffff, arg=0x100cb920) at restart.h:34
    #3 0x0061c7ac in IceUtil::Thread::start(unsigned) (this=0x100cb920,
    stackSize=0) at Thread.cpp:547
    #4 0x00477680 in ConnectionMonitor (this=0x100cb920, instance=@0x7fff7948,
    interval=60) at ConnectionMonitor.cpp:60
    #5 0x004ab58c in IceInternal::Instance::finishSetup(int&, char**) (
    this=0x100cb360, argc=@0x7fff7b40, argv=0x7fff7d74) at Instance.cpp:762
    #6 0x005dda00 in Ice::CommunicatorI::finishSetup(int&, char**) (
    this=0x100cb328, argc=@0x7fff7b40, argv=0x7fff7d74)
    at CommunicatorI.cpp:319
    #7 0x0049c3c0 in Ice::initializeWithPropertiesAndLogger(int&, char**, IceIntern
    al::Handle<Ice::Properties> const&, IceInternal::Handle<Ice::Logger> const&, int
    ) (argc=@0x7fff7b40, argv=0x7fff7d74, properties=@0x7fff7a48,
    logger=@0x7fff7a50, version=30001) at Initialize.cpp:198
    #8 0x0049bca4 in Ice::initialize(int&, char**, int) (argc=@0x7fff7b40,
    argv=0x7fff7d74, version=30001) at Initialize.cpp:154
    #9 0x0041c440 in main (argc=1, argv=0x7fff7d74) at Server.cpp:25
    (gdb)



    I hope it can help you this time !!!
  • benoit
    benoit Rennes, France
    No, I'm afraid this still doesn't help but we're getting close :) The debugger for some reasons stopped when it got a SIG32 signal. You should try to disable the handling of this signal in the debugger:
      $ gdb ./server
      (gdb) handle SIG32 nostop
      (gdb) run
      <the server should start and you should be able to run the client...>
      ...
      <make the server to crash>
      (gdb) where
    

    Benoit.
  • I got it :

    server: ../../../include/IceUtil/Mutex.h:299: IceUtil::Mutex::~Mutex(): Assertio
    n `rc == 0' failed.

    Program received signal SIGABRT, Aborted.
    0x00626978 in __pthread_sigsuspend (set=0x7fff7878)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    53 ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c: No such file or
    directory.
    in ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c
    Current language: auto; currently c
    (gdb) where
    #0 0x00626978 in __pthread_sigsuspend (set=0x7fff7878)
    at ../linuxthreads/sysdeps/unix/sysv/linux/pt-sigsuspend.c:53
    #1 0x00626690 in __pthread_wait_for_restart_signal (self=0x10007ca0)
    at pthread.c:1145
    #2 0x00621144 in __pthread_cond_wait (cond=0x100cb84c, mutex=0x100cb858)
    at restart.h:34
    #3 0x00507e6c in waitImpl<IceUtil::RecMutex> (this=0x100cb84c,
    mutex=@0x100cb858) at Cond.h:203
    #4 0x00506468 in IceUtil::Monitor<IceUtil::RecMutex>::wait() const (
    this=0x100cb84c) at Monitor.h:152
    #5 0x00503d8c in IceInternal::ObjectAdapterFactory::waitForShutdown() (
    this=0x100cb828) at ObjectAdapterFactory.cpp:66
    #6 0x005d9ad4 in Ice::CommunicatorI::waitForShutdown() (this=0x100cb328)
    at CommunicatorI.cpp:119
    #7 0x0041cb70 in main (argc=1, argv=0x7fff7d74) at Server.cpp:29
    (gdb)
  • benoit
    benoit Rennes, France
    I'm afraid your debugger doesn't seem to support threads, it shows the main thread trace instead of showing the trace of the thread responsible for the assert. Does it load the pthread library when you execute the program? If shared library loading is disabled, here's one last thing you could try:
      $ gdb ./server
      (gdb) set auto-solib-add 1
      (gdb) handle SIG32 nostop
      (gdb) run
      <the server should start and you should be able to run the client...>
      ...
      <make the server to crash>
      (gdb) where
    

    Hopefully, it will show the trace of the thread where the assert occured. If it doesn't, I would recommend to upgrade your debugger. You could also try to run your program on another Linux box with a recent distribution (we officially support Fedora Core 4) and see if you also get the crash and can get a better trace.

    Cheers,
    Benoit.
  • I tried this new method.

    I have the same trace as the last one. :(

    I thank you for your help!!

    Merci beaucoup ! ;)
  • benoit
    benoit Rennes, France
    I suspect something's wrong with the threading library of your Montavista distribution. The best way to figure it out is to check if your server works with a recent Linux distribution.

    Also, you should make sure you have the latest patches installed for your Montavista distribution.

    Cheers,
    Benoit.
  • I solved the problem.

    The OPTIMIZE option in config/Make.rules needs to be selected.

    With that option, my server stop crashing after two tries! I can use it as long as I want !!

    Thank you !!
  • benoit
    benoit Rennes, France
    Hi Arnaud,

    I don't think it solved your problem, the assert() from the IceUtil::Mutex::~Mutex destructor is just not triggered anymore because assert() only works for debug builds. The mutex destruction still most likely fails. I don't know if this will cause any other problems but it would be good to find the reason why you get this assert.

    When you built Ice *without* OPTIMIZE enabled, did you try to run the test suite? Does all the tests pass? You can run the test suite with the "./allTests.py" script at the top level of your Ice source distribution.

    Cheers,
    Benoit.
  • Hi Benoit,

    This time I think I may find the problem.

    My TX board is a 64 bits microprocessor (one of my colleague told me that today. But I should have read the datasheet before !!!!) .But I always compiled ICE for 32 bits.

    I compiled ICE with 64 bits and without OPTIMIZE mode.

    The server is running without problem. No crash !!!


    About the tests, all is OK !!

    Thank you very much !!