You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Croteau, Beau" <Be...@ca.com> on 2007/06/14 23:43:01 UTC

Thread Creation/Destruction Problems

I'm running the following code inside of an apache module (actually
inside of a web service running inside an apache module):

apr_thread_t *thd_arr;
apr_pool_create(&ai->mp, NULL);
apr_threadattr_t *thd_attr;
apr_threadattr_create(&thd_attr, (ai->mp));
apr_threadattr_detach_set(thd_attr,1);
apr_thread_create(&thd_arr, thd_attr, ExecuteAction, ai, ai->mp);

The module runs in the mod_gsoap module (it's running as a gsoap web
service).  It's running on Apache 2.2.3 on Windows.

The problem is that we're seeing a thread handle leak.  I can see in the
logs that a thread is created and should be exiting correctly, but when
I use Handle.exe to dump all handles I can still see that the thread ID
is still in the list, even after exiting.  From my debugging it doesn't
appear to be the original handle, but a copy of the handle for some
reason.

I've added the above code into a simple test program and the program
seems to run as expected, the handle count doesn't go up, the threads
are created, and when the threads die the thread count goes down.

I've also used the standard windows ::CreateThread and _beginthread
calls with similar types of 'leaks'.

When I dump the handle list for the apache process I see the thread
handle for the thread that should've since been released.

Has anyone seen such behavior?  It's strange to me and I'll admit that
I'm not completely aware of the Apache internals that would cause
something like this.

Any help would be greatly appreciated.  Thanks.

RE: Thread Creation/Destruction Problems

Posted by "Croteau, Beau" <Be...@ca.com>.
Unfortunately, I have tried that route and the same thing occurs.  APR uses CreateThread and ExitThread as the underlying calls and the same 'leak' occurs.


-----Original Message-----
From: William A. Rowe, Jr. [mailto:wrowe@rowe-clan.net]
Sent: Sun 6/17/2007 2:50 PM
To: dev@httpd.apache.org
Subject: Re: Thread Creation/Destruction Problems
 
Croteau, Beau wrote:
> I've investigated further and the problem appears to have something to do with the mod_ssl module or a part of it's thread hooks.
> 
> In my test server I create a thread using _beginthread(...) which means when the thread returns it should clean up after itself.
> 
> If I comment out the line:
> LoadModule ssl_module modules/mod_ssl.so
> 
> Then the server application functions as expected, when I don't it leaks a thread handle every call.

Please don't read Win32 API logic as gospel when you are trying to plug
into another application's framework.  In this case, httpd used APR's
threading API so everything cooperates; we then initialize openssl lib
to trust APR for the threading information it requires.  APR is implemented
on top of the Win32 API when running on windows, but it doesn't stop there.

You are better off using apr_thread_create, etc.  First, it makes your
code more portable.  More importantly, it lets your code interoperate
within httpd :)  See apr_thread_proc.h for details, or test/testthread.c
in the apr sources for an example.



Re: Thread Creation/Destruction Problems

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Croteau, Beau wrote:
> I've investigated further and the problem appears to have something to do with the mod_ssl module or a part of it's thread hooks.
> 
> In my test server I create a thread using _beginthread(...) which means when the thread returns it should clean up after itself.
> 
> If I comment out the line:
> LoadModule ssl_module modules/mod_ssl.so
> 
> Then the server application functions as expected, when I don't it leaks a thread handle every call.

Please don't read Win32 API logic as gospel when you are trying to plug
into another application's framework.  In this case, httpd used APR's
threading API so everything cooperates; we then initialize openssl lib
to trust APR for the threading information it requires.  APR is implemented
on top of the Win32 API when running on windows, but it doesn't stop there.

You are better off using apr_thread_create, etc.  First, it makes your
code more portable.  More importantly, it lets your code interoperate
within httpd :)  See apr_thread_proc.h for details, or test/testthread.c
in the apr sources for an example.

RE: Thread Creation/Destruction Problems

Posted by "Croteau, Beau" <Be...@ca.com>.
I've investigated further and the problem appears to have something to do with the mod_ssl module or a part of it's thread hooks.

In my test server I create a thread using _beginthread(...) which means when the thread returns it should clean up after itself.

If I comment out the line:
LoadModule ssl_module modules/mod_ssl.so

Then the server application functions as expected, when I don't it leaks a thread handle every call.



-----Original Message-----
From: Croteau, Beau [mailto:Beau.Croteau@ca.com]
Sent: Thu 6/14/2007 5:43 PM
To: dev@httpd.apache.org
Subject: Thread Creation/Destruction Problems
 
I'm running the following code inside of an apache module (actually
inside of a web service running inside an apache module):

apr_thread_t *thd_arr;
apr_pool_create(&ai->mp, NULL);
apr_threadattr_t *thd_attr;
apr_threadattr_create(&thd_attr, (ai->mp));
apr_threadattr_detach_set(thd_attr,1);
apr_thread_create(&thd_arr, thd_attr, ExecuteAction, ai, ai->mp);

The module runs in the mod_gsoap module (it's running as a gsoap web
service).  It's running on Apache 2.2.3 on Windows.

The problem is that we're seeing a thread handle leak.  I can see in the
logs that a thread is created and should be exiting correctly, but when
I use Handle.exe to dump all handles I can still see that the thread ID
is still in the list, even after exiting.  From my debugging it doesn't
appear to be the original handle, but a copy of the handle for some
reason.

I've added the above code into a simple test program and the program
seems to run as expected, the handle count doesn't go up, the threads
are created, and when the threads die the thread count goes down.

I've also used the standard windows ::CreateThread and _beginthread
calls with similar types of 'leaks'.

When I dump the handle list for the apache process I see the thread
handle for the thread that should've since been released.

Has anyone seen such behavior?  It's strange to me and I'll admit that
I'm not completely aware of the Apache internals that would cause
something like this.

Any help would be greatly appreciated.  Thanks.