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/02/10 01:33:55 UTC

[jira] Commented: (MODPYTHON-109) Signal handler calling Py_Finalize() when child processes being killed.

    [ http://issues.apache.org/jira/browse/MODPYTHON-109?page=comments#action_12365805 ] 

Graham Dumpleton commented on MODPYTHON-109:
--------------------------------------------

The problem is actually bigger than just Py_Finalize(). When a server cleanup handler is registered using either apache.register_cleanup() or req.server.register_cleanup(), the execution of that handler is also registered to be called by associating it with the destruction of the main child memory pool. This means that such server cleanup handlers are also going to be executed from the context of a signal handler and thus are going to be a problem. It may be necessary to remove the feature of registering server cleanup handlers as there seems to be no other way of doing the same thing.

> Signal handler calling Py_Finalize() when child processes being killed.
> -----------------------------------------------------------------------
>
>          Key: MODPYTHON-109
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-109
>      Project: mod_python
>         Type: Bug
>   Components: core
>     Versions: 3.2
>     Reporter: Graham Dumpleton

>
> When Apache is killing off child processes as part of actions taken when the "apachectl restart" or "apachectl graceful" command is run, it sends a SIGTERM signal to the child processes. This causes a signal handler registered by Apache to be run. That signal handler destroys the main child memory pool. That memory pool has though a cleanup handler associated with it which was registered by mod_python. That cleanup handler ultimately calls Py_Finalize().
> The problem with this is that Py_Finalize() isn't safe to be called from a signal handler and if a handler is still executing or there is a separate thread running in the context of Python, a deadlock will likely ensue. This will prevent the child process exiting due to the SIGTERM causing the Apache parent process to send it a SIGKILL to really kill it.
> For a more detailed assessment of the problem and what lead to this conclusion see:
>   http://www.modpython.org/pipermail/mod_python/2006-January/019865.html
>   http://www.modpython.org/pipermail/mod_python/2006-January/019866.html
>   http://www.modpython.org/pipermail/mod_python/2006-January/019870.html
> To avoid the problem, the only choice seems to be avoid calling Py_Finalize() from the signal handler. The simplistic way of doing this seems to be to add:
>      if (child_init_pool)
>          return APR_SUCCESS;
> at the start of python_finalize(). This will mean that Py_Finalize() is never called in child processes. The full consequences of this is unknown, but on face value it would seem that it might be a reasonable thing to do. More research may be required.

-- 
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