You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-dev@quetz.apache.org by "Graham Dumpleton (JIRA)" <ji...@apache.org> on 2006/10/24 08:05:17 UTC

[jira] Commented: (MODPYTHON-195) Possible leaking of Win32 event handles when Apache restarted.

    [ http://issues.apache.org/jira/browse/MODPYTHON-195?page=comments#action_12444208 ] 
            
Graham Dumpleton commented on MODPYTHON-195:
--------------------------------------------

Jeff provides the following further information. The question is whether there is a more accepted way of doing this now as that email was from two years ago and that it is dependent on something that change from release to release is a problem. Maybe a simple static variable can be used to determine if call has already been made since on the restart, the mod_python module should by rights be unloaded from memory which means the static should get reset to 0, thus first call could always be setting it to 1 and second call not doing anything it already 1.


Anyway, Jeffs email follows:

I added some logging to python_init in mod_python.c to try to understand what is going on.  Apparently when you run apache as a service on win32 the python_init function gets called TWICE on restart (I have no idea why) and the first time is somehow spurious (perhaps it is running in the context of the parent process that spawns the child process that really services requests?)
yet python_init allocates stuff anyway which never gets freed, for example the "interpreters_lock" allocated via
apr_thread_mutex_create(&interpreters_lock, APR_THREAD_MUTEX_UNNESTED, p);


I found this posting on the web
http://mail-archives.apache.org/mod_mbox/httpd-dev/200311.mbox/%3C3FAF9D1E.2020002@wstoddard.com%3E
which seems to agree that the  ap_hook_post_config callback gets called twice on win32 running as a service and suggested this hack:

#ifdef WIN32
    /* Do not run post_config in the Windows parent process
     * The envar AP_PARENT_PID is set in the env list (by mpm_winnt)
     * for the child process.
     * **WARNING**:
     * This check is not as robust as I would like because the name of
this
     * envar is subject to change from release to release.
     */
    if (!getenv("AP_PARENT_PID")) {
        return OK;
    }
#endif

I put this into python_init() just to see what would happen and sure enough, the leaking 4 handles went away.  I don't know what to do at this point since I am uncomfortable with the hack.  Yet clearly python_init() is not expecting to be called twice on restart.  Is this an apache bug or a well-know (heh) feature that modules must protect themselves against?


> Possible leaking of Win32 event handles when Apache restarted.
> --------------------------------------------------------------
>
>                 Key: MODPYTHON-195
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-195
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.10
>            Reporter: Graham Dumpleton
>
> Jeff Robins in:
>   http://mail-archives.apache.org/mod_mbox/httpd-python-dev/200610.mbox/%3c3308644A-9EE5-48BA-845F-EF3F43BB68FF@dscpl.com.au%3e
> indicates a belief that when an Apache restart is performed on Windows that there are a number of Win32 event handles leaked. His belief is that this seems to be linked to mod_python.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira