You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Tacalau Daniel Stefan <da...@avira.com> on 2007/09/11 15:40:50 UTC

Problem with pool integrity check for apr threads

Hello,

I'm using apr in a larger project which makes heavy usage of apr
threads. Recently I got over a problem when I compiled apr with
"--enable-pool-debug=yes":

- apr_pool_check_integrity will assert at the ownership test  for
apr_thread_exit

The problem is that apr_thread_exit destroys a pool allocated on another
thread. This pool is created in apr_thread_create and is the pool in
which the thread resources are allocated. Of course this pool cannot be
created in the thread that will start, but in the parent thread.

So the thread trying to do destroy in apr_thread_exit does not have
ownership of the pool. apr_thread_exit must be called from the thread
who wants to exit since it calls pthread_exit.

How should I deal with this problem?

-- 
Best regards,

Daniel Tacalau



Re: Problem with pool integrity check for apr threads

Posted by Tacalau Daniel Stefan <da...@avira.com>.
Tacalau Daniel Stefan wrote:
> Joe Orton wrote:
>   
>> Can you file a bug on this in bugzilla?
>>
>> joe
>>   
>>     
> A solution would be for apr_thread_exit() to not call apr_pool_destroy()
> since it the exiting thread does now own the pool and leave this to the
> thread parent. 
>   
What I meant was - a solution would be for apr_thread_exit() to not call
apr_pool_destroy()since the exiting thread does not own the pool and
leave this to the thread parent.

The bug associated with this issue - bug 43375 Pool integrity check
fails for apr threads.

Re: Problem with pool integrity check for apr threads

Posted by Joe Orton <jo...@redhat.com>.
On Thu, Sep 13, 2007 at 11:22:11AM +0300, Tacalau Daniel Stefan wrote:
> Joe Orton wrote:
> > I guess this is one part of the pool-debug code which never got tested!  
> > This can be fixed either by some convoluted hack to change the pool 
> > ownership after apr_thread_create(), or simply by moving the thread 
> > creation later in apr_thread_create().  The latter would be simpler.  
> > Can you file a bug on this in bugzilla?
> >
> > joe
> >   
> Thread creation is the last operation done by apr_thread_create().

Sorry, I meant the other way round but that makes no sense either, so 
ignore me :)

> A solution would be for apr_thread_exit() to not call 
> apr_pool_destroy() since it the exiting thread does now own the pool 
> and leave this to the thread parent. This will comply with 
> apr_pool_check_integrity requirements.
> 
> How important is the apr_pool_check_integrity's owneship test (do not
> release on a thread resources allocated in  a pool that belongs to
> another thread)? Can this lead to crashes or leaks?

All this stuff is just debugging code, it doesn't necessarily imply a 
problem in a production build.  This one aims to find places where a 
thread uses a pool created in another thread (generally unexpected, 
supposedly).

You could just work around this passing a different argument to 
--enable-pool-debug so you don't get the APR_POOL_DEBUG_OWNER checks. 
Thanks for filing the PR.

Regards,

joe

Re: Problem with pool integrity check for apr threads

Posted by Tacalau Daniel Stefan <da...@avira.com>.
Joe Orton wrote:
> I guess this is one part of the pool-debug code which never got tested!  
> This can be fixed either by some convoluted hack to change the pool 
> ownership after apr_thread_create(), or simply by moving the thread 
> creation later in apr_thread_create().  The latter would be simpler.  
> Can you file a bug on this in bugzilla?
>
> joe
>   
Thread creation is the last operation done by apr_thread_create(). A
solution would be for apr_thread_exit() to not call apr_pool_destroy()
since it the exiting thread does now own the pool and leave this to the
thread parent. This will comply with apr_pool_check_integrity requirements.

How important is the apr_pool_check_integrity's owneship test (do not
release on a thread resources allocated in  a pool that belongs to
another thread)? Can this lead to crashes or leaks?

I'll fill a bug report!

-- 
Best regards,

Daniel Tacalau


Re: Problem with pool integrity check for apr threads

Posted by Joe Orton <jo...@redhat.com>.
On Tue, Sep 11, 2007 at 04:40:50PM +0300, Tacalau Daniel Stefan wrote:
> - apr_pool_check_integrity will assert at the ownership test  for
> apr_thread_exit
> 
> The problem is that apr_thread_exit destroys a pool allocated on another
> thread. This pool is created in apr_thread_create and is the pool in
> which the thread resources are allocated. Of course this pool cannot be
> created in the thread that will start, but in the parent thread.
> 
> So the thread trying to do destroy in apr_thread_exit does not have
> ownership of the pool. apr_thread_exit must be called from the thread
> who wants to exit since it calls pthread_exit.
> 
> How should I deal with this problem?

I guess this is one part of the pool-debug code which never got tested!  
This can be fixed either by some convoluted hack to change the pool 
ownership after apr_thread_create(), or simply by moving the thread 
creation later in apr_thread_create().  The latter would be simpler.  
Can you file a bug on this in bugzilla?

joe