You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Stephen Bartnikowski <sb...@barkinglizards.com> on 2006/12/13 00:22:16 UTC

Linux deconstruction order problem

Hi,

I'm having a problem on shutdown of my application, but only on Linux. I've
attached the stack trace of the last thread at the bottom of this message. 

>From what I can tell, in frame 3, apr_atomic_casptr is attempting to lock a
mutex, but the mutex has already been destroyed. This consistently causes my
application to abort.  The mutex is initialized the first time
APRInitializer::getInstance is called.  

I'm wondering if the call order could be changed somehow on destruction.
However, frame 6 of my core dump is showing me that the object being
destroyed is a static class member variable, and I don't have any control
over when those are initialized or destroyed.

I think it may be related to bug 159, but that bug is reporting a seg fault,
so I'm not sure if this is related.  Does any one have any suggestions for
working around this?

Thanks,
Steve

#0  0xffffe410 in __kernel_vsyscall ()
#1  0xb76fe7d0 in raise () from /lib/libc.so.6
#2  0xb76ffea3 in abort () from /lib/libc.so.6
#3  0xb7ae118e in apr_atomic_casptr () from /usr/local/lib/liblog4cxx.so
#4  0xb79fc34d in log4cxx::helpers::ObjectPtrBase::exchange () from
/usr/local/lib/liblog4cxx.so
#5  0x0805ff67 in ~ObjectPtrT (this=0xb7b7c7e4) at
/usr/local/include/log4cxx/helpers/objectptr.h:73
#6  0xb7b63ecc in __tcf_1 () at Message.cpp:14
#7  0xb7701566 in __cxa_finalize () from /lib/libc.so.6
#8  0xb7b63c63 in __do_global_dtors_aux () from
/home/sbart/blt/projects/blt/server/blits/server/sdk/impl/libgsutil.so.1_5
#9  0xb7b7556c in _fini () from
/home/sbart/blt/projects/blt/server/blits/server/sdk/impl/libgsutil.so.1_5
#10 0xb7f8adc5 in _dl_fini () from /lib/ld-linux.so.2
#11 0xb770126d in exit () from /lib/libc.so.6
#12 0xb76eb884 in __libc_start_main () from /lib/libc.so.6
#13 0x08056201 in _start ()


RE: Linux deconstruction order problem

Posted by Stephen Bartnikowski <sb...@barkinglizards.com>.
> There are two scenarios where I have seen this type of problem (three  
> if you include deviations from spec in earlier gcc's): destruction of  
> the Level constants (Level::OFF etc) that appear at the end of src/ 
> level.cpp and logging taking place during the destruction of static  
> objects.

> You might try commenting out Level::OFF et al from include/log4cxx/ 
> level.h and the constructors at the bottom of src/level.cpp.  log4cxx  
> shouldn't need them since it uses the equivalent Level::getOff() et  
> al methods.  They have been kept for compatibility with earlier  
> versions of log4cxx but been problematic and should likely be  
> removed.  I can't tell from the stack trace if you are running into  
> this problem or something else.

Hi Curt,

Thanks for the idea.  I gave it shot, but I think my problem is unrelated.

This crash I'm getting is happening with a LoggerPtr object that I've
declared as static.  When the LoggerPtr object is being cleaned up on exit,
the ObjectPtrT destructor is called, which ultimately calls
apr_atomic_casptr that blows up.  It looks like the apr method is trying to
lock a mutex that's already been cleaned up.

If I make the offending LoggerPtr object a class member, exit continues
until the next statically-allocated LoggerPtr object.  Making each LoggerPtr
object a member rather than a static member is less than ideal for my
application, so I'd prefer not to go that route.

Is there a way to de-initialize a statically-allocated LoggerPtr before exit
is called?  Maybe if the static members are allocated with new memory, and
then delete them before exit?  Is there an easier way to get around this?

Thanks!
Steve



Re: Linux deconstruction order problem

Posted by Curt Arnold <ca...@apache.org>.
On Dec 12, 2006, at 5:22 PM, Stephen Bartnikowski wrote:

> Hi,
>
> I'm having a problem on shutdown of my application, but only on  
> Linux. I've
> attached the stack trace of the last thread at the bottom of this  
> message.
>
> From what I can tell, in frame 3, apr_atomic_casptr is attempting  
> to lock a
> mutex, but the mutex has already been destroyed. This consistently  
> causes my
> application to abort.  The mutex is initialized the first time
> APRInitializer::getInstance is called.
>
> I'm wondering if the call order could be changed somehow on  
> destruction.
> However, frame 6 of my core dump is showing me that the object being
> destroyed is a static class member variable, and I don't have any  
> control
> over when those are initialized or destroyed.
>
> I think it may be related to bug 159, but that bug is reporting a  
> seg fault,
> so I'm not sure if this is related.  Does any one have any  
> suggestions for
> working around this?
>
> Thanks,
> Steve


There are two scenarios where I have seen this type of problem (three  
if you include deviations from spec in earlier gcc's): destruction of  
the Level constants (Level::OFF etc) that appear at the end of src/ 
level.cpp and logging taking place during the destruction of static  
objects.

You might try commenting out Level::OFF et al from include/log4cxx/ 
level.h and the constructors at the bottom of src/level.cpp.  log4cxx  
shouldn't need them since it uses the equivalent Level::getOff() et  
al methods.  They have been kept for compatibility with earlier  
versions of log4cxx but been problematic and should likely be  
removed.  I can't tell from the stack trace if you are running into  
this problem or something else.