Archived

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

IceGrid + waitForShutdown without Ice::Application -- doesn't work in C++

I've been seeing sort of weird behaviour. It appears that, if I want waitForShutdown() to work properly when I shut down a server from IceGrid, I need to use Ice::Application for the server -- if I just call Ice::initialize and then waitForShutdown(), the wait never returns. In the IceGrid GUI, it says "Deactivating" with the little red minus sign until the timeout expires, and then the server is killed forcibly.

This is only in C++, as far as I can tell; in Java, for instance, the exactly analogous code seems to be happy.

Here's the source of my C++ server that's causing the problem:
#include <Ice/Ice.h>
#include <iostream>
int main (int argc, char* argv[]) {
	Ice::CommunicatorPtr ic = Ice::initialize (argc, argv);
	std::cerr << "Added adapter" << std::endl;
	ic->waitForShutdown();
	std::cerr << "Shut down!!" << std::endl;
	return EXIT_SUCCESS;
}

Is there some extra magic in Ice::Application that makes this work?

MEF

Comments

  • benoit
    benoit Rennes, France
    IceGrid tries to cleanly shutdown the server before killing it, that's why it hangs in your case because your server doesn't have any way to be "cleanly" shutdown.

    To cleanly shutdown a server, an IceGrid node uses the process proxy registered by the server (see section 30.17.6 of the Ice manual) or if this proxy isn't registered, on Unix platforms it tries to send a SIGQUIT signal (Ice::Application installs a signal handler to handle SIGQUIT signal and destroy or shutdown the communicator).

    Let us know if you need more information!

    Cheers,
    Benoit.
  • Wow! Prompt response, thanks!

    Unfortunately, for (the real version of) this server, there is actually no adapter -- from an Ice perspective it's technically a client, except that it's started and stopped by IceGrid. (It's a vision module that broadcasts its output to other parts of the system, if you're wondering what the point is.) Section 30.17.6 of the documentation describes setting properties on *adapters*. I suppose I could create a dummy adapter just to set that property; would that work?

    If so, that sounds like the easiest solution; if not, it looks like I'm probably going to need to register my own SIGQUIT handler based on the one that's in Ice::Application. Okay, that's not too horrible in either case, I guess.

    MEF
  • benoit
    benoit Rennes, France
    Oops, sorry, it's actually *not* SIGQUIT that the IceGrid node is sending to the process, it's SIGTERM.

    Yes, you can create a dummy object adapter just for the purpose of shutting down the server. That's the most portable solution as signals don't work on Windows. If you want to go the signal route though, I would recommend to simply use Ice::Application.

    Cheers,
    Benoit.
  • You could also use the IceUtil::CtrlCHandler directly, that Ice::Application uses.
  • benoit wrote: »
    Yes, you can create a dummy object adapter just for the purpose of shutting down the server.

    Tried this; works well.
    benoit wrote: »
    If you want to go the signal route though, I would recommend to simply use Ice::Application.

    Yeah, that would be the obvious way to do it. However, this is me adding an Ice interface to somebody else's program, and they're not crazy about changing their "main" method.
    marc wrote: »
    You could also use the IceUtil::CtrlCHandler directly, that Ice::Application uses.

    Hmm, that's a possibility ... must investigate further.

    Thanks for all the very prompt and helpful suggestions!

    MEF