Archived

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

Deadlock When server calls client via proxy

I'm implementing a data server. Clients of the data server register with the data server and receive an ID number. As part of the registration process, when this ID number is determined the server finalizes the registration by calling a method on the client (via a proxy to the client passed to the server). This call from the Data Server to the client results in a deadlock. I have tried setting Ice.ThreadPool.Client.Size and Ice.ThreadPool.Server.Size to high numbers but it doesn't help. When Ice.Trace.ThreadPool is set to 1 it shows the threadpools shrinking.

Setting the Object Adapter thread pools to high numbers gives the same results.
interface DataClient{
	void finalizeRegistration(int id);
};

interface DataServer{
		void receiveRequest(DataRequest r);
		int registerClient(DataClient* dc) throws ClientRegisteredException;
		void unregisterClient(DataClient* dc);
		void heartbeat(int clientid);
};
Ice::Int DataServerI::registerClient(const QuoteServer::DataClientPrx& dc, const Ice::Current& current){
	//check to see if registered, if registered throw exception
        ...

	//assign clientID, add to map of registered clients
         ...


	std::cout << "Calling finalizeRegistration on new client:" << dc << std::endl;
	dc->finalizeRegistration(cid);
	std::cout << "Done Finalizing Registration " << std::endl;

	return cid;
}
void DataClientI::finalizeRegistration(::Ice::Int id, const Ice::Current& c){
	the_heart->setClientId(id);
	heart_control = the_heart->start();
}

Now, it seems a simple way around this would be to have the client finalize its own registration using the client id returned from the call to registerClient(), and that is probably what I will end up doing, but I want to understand why this would deadlock because I will definitely need to use nested callbacks at some point.

Any help would be greatly appreciated.

Comments

  • mes
    mes California
    Hi,

    Welcome to the forum.

    The most common reason for a hang during an invocation is when you neglect to activate your object adapter. You said the hang occurs during the server's callback to the client, so verify that you've activated the object adapter in the client.

    The default thread pool configuration supports one level of nested twoway invocations (client => server => client), so it shouldn't be necessary to increase the size of the thread pools for your example to work correctly.

    You can also enable network and protocol tracing in the client to see exactly which messages are being sent and received.

    Regards,
    Mark
  • That was it. Thank you so much for the help.