1

I have used one pthread for polling network every 2 secs. For this I am calling one Client Interface from run() method of pthread. But what is happening when network is down between server and client this method should throw exception, but this is not happening right now.So what I planning is to forcefully return this method and exit the thread.

To achieve this I have tried to forcefully exit from thread by signaling it. But the problem I am still facing is that after exitting from thread itself client inteface is throwing exception very late.This leading to inconsistent behaviour in my implementation.

My code looks like this

//server side code
//This is Linux code

void ServerImp::run()
{
  try {
  while(1)
  {
    Client->PingNetwork()
  }
  }
  catch(...)
  {
    //Handle exception
  }

}

//PingNetwork implementation
//This is Windows code
void NetworkImpl::PingNetwork() throw exception
{
  try{
  while(IsValidClient())//This will return as soon as client disconnected from server
  {
     sleep(2);
  }
  }
  catch(...)
  {
     //Handle exception
  }
}

Basic idea to ask this question is that for me my underlying interace TAO 2.0a is not detecting network failure immediately for current session but on client side it detect it well in time and initiate one more new session for connection.But after sometime both new and old session got CORBA::COMM_FAILURE exception so it leading to unstable behaviour in server and client. Is that something TAO limitation? or I have to do something to make it work. Please help me out if is there any way to work around here.

Thanks

linux user
  • 21
  • 4
  • No idea what your code does or what your question is. – Lightness Races in Orbit Jul 20 '15 at 13:00
  • 1
    There is a purpose for attempting to create a mcve. Also, my mcve efforts have identified my mistake. Give it a try. (Q count still 0, sigh.) – 2785528 Jul 20 '15 at 14:38
  • 1
    Perhaps you should be looking at a solution to the cause of the issue, which sounds like a timeout issue. There's probably a setsocketopt to reduce the timeout and then you can handle the exception correctly. – Richard Jul 21 '15 at 06:25
  • Hi Richard thanks, but problem l am facing here is that network is disconnected but PingNetwork() is not returning and If I am using timeout also then later new connections are also getting imapcted by this. So I am looking to make it return normally when network gone. – linux user Jul 21 '15 at 10:29
  • You should set a CORBA Messaging TimeOut policy to explicitly set how long you want to wait for a reply. Now you probably get a TCPIP wait time, 30 seconds or more. – Johnny Willemsen Jul 22 '15 at 12:11
  • @Johnny now its taking sometimes 10 minutes to return from call after disconnection. And I have used timeout policy also but newer session is also affected if timeout happens for old session.Newer session also getting either COMM_FAILURE or TIMEOUT.And this making situation even more unstable(continous connection followed by disconnection). – linux user Jul 22 '15 at 12:53
  • You shouldn't ping faster then your timeout setting, so if you ping each 2 sec allow a maximum response time of 1 second. – Johnny Willemsen Jul 22 '15 at 16:24
  • @Johnny, is that make any difference? If yes how? we have to give some definite time before timeout say 15 sec,30 sec. – linux user Jul 23 '15 at 05:36
  • At the moment you ping faster then your timeout you get a list of pending invocations that all will also cause exceptions. I would personally use an ACE event handler registered on the ACE reactor to trigger the timed ping, not use a sleep, they are bad. – Johnny Willemsen Jul 23 '15 at 06:36

1 Answers1

0

It sounds like your force exited thread is not exited cleanly. A cleanly exited thread should have all its context destroyed and not leaving any residue. The pthread can be either joinable or detached, which type of thread creation you use? After your force exit happen, does your "Client" object destroyed? What about the logic that creates the thread, does it handle exception of a zombie thread? Answer all theses question yourself and handles all these details.

simon
  • 391
  • 1
  • 9
  • Simon,I have created pthread without any option, so it means it will be joinable by default. And yes I am handling exception if it occur during execution of the thread function. – linux user Jul 23 '15 at 05:52
  • Perhaps you should do a try catch statement right at the main() of your application to catch everything. Set a break point there and see what you caught when exception happens. From there you can start narrow down your issue. – simon Jul 23 '15 at 06:58