[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4cxx-dev
Subject:    [jira] [Updated] (LOGCXX-451) Application hang up during exit on Windows
From:       "John.Rembo (JIRA)" <log4cxx-dev () logging ! apache ! org>
Date:       2014-12-30 9:47:13
Message-ID: JIRA.12764168.1419932487000.114163.1419932833544 () Atlassian ! JIRA
[Download RAW message or body]


     [ https://issues.apache.org/jira/browse/LOGCXX-451?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel \
]

John.Rembo updated LOGCXX-451:
------------------------------
    Description: 
I use such code in one of my DLL in application:
  xml::DOMConfigurator::configureAndWatch("log4cxx.xml");
  PropertyConfigurator::configureAndWatch("log4cxx.properties");
At this point watchdog threads are created and they are pushed to some container:
void DOMConfigurator::configureAndWatch(const std::string& filename, long delay)
{
        File file(filename);
#if APR_HAS_THREADS
		if( xdog )
		{
			APRInitializer::unregisterCleanup(xdog);
			delete xdog;
		}
        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);   < == watchdog pushed to container \
here  xdog->setDelay(delay);
        xdog->start();
#else
    DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif        
}

void APRInitializer::registerCleanup(FileWatchdog* watchdog) {
    APRInitializer& instance(getInstance());
#if APR_HAS_THREADS
    synchronized sync(instance.mutex);
#endif
    instance.watchdogs.push_back(watchdog);
}

But APRInitializer is a Singletone class which is allocated static.
APRInitializer& APRInitializer::getInstance() {
  static APRInitializer init;
  return init;
}

Then my application stops and Dynamic Library, which uses log4cxx is unloaded in \
_CRT_INIT (which is called from DllMain) function destructor for APRInitializer \
object is called => and called destructors for watchdog objects.

FileWatchdog::~FileWatchdog() {
   apr_atomic_set32(&interrupted, 0xFFFF);
   try {
        thread.interrupt();
        thread.join();
   } catch(Exception &e) {
   }
}

In thread.join() function WaitForSingleObject is called and we have deadlock, because \
when some thread execute DllMain code all other threads are slept by system. So, one \
thread wait when another will stop, but another thread is slept.

Now it is impossible to call configureAndWatch from Dll.
Please fix it?

  was:
I use such code in one of my DLL in application:
  xml::DOMConfigurator::configureAndWatch("log4cxx.xml");
  PropertyConfigurator::configureAndWatch("log4cxx.properties");
At this point watchdog threads are created and they are pushed to some container:
void DOMConfigurator::configureAndWatch(const std::string& filename, long delay)
{
        File file(filename);
#if APR_HAS_THREADS
		if( xdog )
		{
			APRInitializer::unregisterCleanup(xdog);
			delete xdog;
		}
        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);   < == watchdog pushed to container \
here  xdog->setDelay(delay);
        xdog->start();
#else
    DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
#endif        
}

void APRInitializer::registerCleanup(FileWatchdog* watchdog) {
    APRInitializer& instance(getInstance());
#if APR_HAS_THREADS
    synchronized sync(instance.mutex);
#endif
    instance.watchdogs.push_back(watchdog);
}

But APRInitializer is a Singletone class which is allocated static.
APRInitializer& APRInitializer::getInstance() {
  static APRInitializer init;
  return init;
}

Then my application stops and Dynamic Library, which uses log4cxx is unloaded in \
_CRT_INIT (which is called from DllMain) function destructor for APRInitializer \
object is called => and called destructors for watchdog objects.

FileWatchdog::~FileWatchdog() {
   apr_atomic_set32(&interrupted, 0xFFFF);
   try {
        thread.interrupt();
        thread.join();
   } catch(Exception &e) {
   }
}

In thread.join() function WaitForSingleObject is called and we have deadlock, because \
when some thread execute DllMain code all other threads are slept by system. So, one \
thread wait when another will stop, but another thread is slept.

So now it is impossible to call configureAndWatch from Dll.
Can you fix it?


> Application hang up during exit on Windows
> ------------------------------------------
> 
> Key: LOGCXX-451
> URL: https://issues.apache.org/jira/browse/LOGCXX-451
> Project: Log4cxx
> Issue Type: Bug
> Components: Configurator
> Affects Versions: 0.11.0
> Environment: Windows
> Reporter: John.Rembo
> 
> I use such code in one of my DLL in application:
> xml::DOMConfigurator::configureAndWatch("log4cxx.xml");
> PropertyConfigurator::configureAndWatch("log4cxx.properties");
> At this point watchdog threads are created and they are pushed to some container:
> void DOMConfigurator::configureAndWatch(const std::string& filename, long delay)
> {
> File file(filename);
> #if APR_HAS_THREADS
> 		if( xdog )
> 		{
> 			APRInitializer::unregisterCleanup(xdog);
> 			delete xdog;
> 		}
> xdog = new XMLWatchdog(file);
> APRInitializer::registerCleanup(xdog);   < == watchdog pushed to container here
> xdog->setDelay(delay);
> xdog->start();
> #else
> DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
> #endif        
> }
> void APRInitializer::registerCleanup(FileWatchdog* watchdog) {
> APRInitializer& instance(getInstance());
> #if APR_HAS_THREADS
> synchronized sync(instance.mutex);
> #endif
> instance.watchdogs.push_back(watchdog);
> }
> But APRInitializer is a Singletone class which is allocated static.
> APRInitializer& APRInitializer::getInstance() {
> static APRInitializer init;
> return init;
> }
> Then my application stops and Dynamic Library, which uses log4cxx is unloaded in \
> _CRT_INIT (which is called from DllMain) function destructor for APRInitializer \
> object is called => and called destructors for watchdog objects. \
> FileWatchdog::~FileWatchdog() { apr_atomic_set32(&interrupted, 0xFFFF);
> try {
> thread.interrupt();
> thread.join();
> } catch(Exception &e) {
> }
> }
> In thread.join() function WaitForSingleObject is called and we have deadlock, \
> because when some thread execute DllMain code all other threads are slept by \
> system. So, one thread wait when another will stop, but another thread is slept.
> Now it is impossible to call configureAndWatch from Dll.
> Please fix it?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic