Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-278

Threads for reconnecting sockets do not end cleanly when program exits



    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.11.0
    • Component/s: Appender
    • Labels:
    • Environment:
      On Windows at least


      When I have other threads running like the one to do reconnection to a socket then my app does not shut down cleanly. When it ends I get this message on the console:

      This application has requested the Runtime to terminate it in an unusual way.
      Please contact the application's support team for more information.

      and I get an unknown software exception (0x40000015).

      If I add an XMLSocketAppender (with the fix for bug LOG4CXX-277) and the thread is sleeping then when main exits there is a delay (equal to the reconnectionDelay) then the exception occurs. I think the problem is that the SocketAppender is destroyed but the monitor thread is continuing to sleep when it wakes up it is not checking if it was interrupted like FileWatchdog does.

      I can get rid of the exception by doing a thread.join in the close method and changing the monitor code to check for being interrupted like this:

      if( !socketAppender->thread.interrupted() )

      { LogLog::debug(LogString(LOG4CXX_STR("Attempting connection to ")) + socketAppender->address->getHostName()); socket = new Socket(socketAppender->address, socketAppender->port); Pool p; socketAppender->setSocket(socket, p); LogLog::debug(LOG4CXX_STR("Connection established. Exiting connector thread.")); }

      return NULL;

      But that does not get rid of the delay waiting for the sleep to end. I don't understand why the sleep is not interrupted in this thread, but FileWatchdog does not have the same problem. The call to sleep from FileWatchdog does not keep the app from exiting. The sleep in FileWatchdog does not return if it is sleeping when the app exits.




            • Assignee:
              carnold@apache.org Curt Arnold
              dalewking Dale King
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: