Exit/shutdown/cleanup procedure

40 views
Skip to first unread message

Marco Vimercati

unread,
Sep 17, 2015, 9:51:44 AM9/17/15
to qjsonrpc-development
Hi Matt,
i found a little problem playing with qjsonrpc.
My service/server expose a "stop" method that should close the server application itself.
When the stop() method is invoked by the client I emit a queued signal ( Qt::QueuedConnection ) to a method (in the same object) that
should stop and close the service; something like this:

if (tcpServer->isListening()) {
tcpServer->removeService(service);
tcpServer->close();
}
delete tcpServer;

The QueuedConnection (instead of default DirectConnection) avoids delete of the service/server object before the stop() method returns a value to the client.
In fact in the log messages I can see the reply sent from the server

received( QJsonRpcSocket(0x4b2278) ):  "{"id":30,"jsonrpc":"2.0","method":"component.stop","params":[4]}"
....
sending( QJsonRpcSocket(0x4b2278) ):  "{"id":30,"jsonrpc":"2.0","result":0}"

Unfortunatelly the client never receive this response, and this produces a lock in my code.
I suspect that the close() /delete are executed before the reply is transmitted through the socket (but after the writeData on socket,
as the log message says). In this case I usually put a flush() of the socket before closing it (I suppose this could fix the problem), but I'm not able
to access the client's sockets with qjsonrpc lib.
What do you think about? Any idea?

best regards
Marco

Marco Vimercati

unread,
Sep 17, 2015, 9:53:49 AM9/17/15
to qjsonrpc-development
I forget to say that adding a delay (let's say 100ms) before the server's close/delete fix the problem,
but I think it's not a clean solution and probably it is not deterministic
Reply all
Reply to author
Forward
0 new messages