Issue Details (XML | Word | Printable)

Key: MODPYTHON-109
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Signal handler calling Py_Finalize() when child processes being killed.

Created: 07/Jan/06 07:53 PM   Updated: 11/May/07 05:10 AM
Return to search
Component/s: core
Affects Version/s: 3.2.7
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works MP109_20060308_grahamd_1.diff 2006-03-08 06:51 PM Graham Dumpleton 5 kB


 Description  « Hide
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.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton made changes - 26/Feb/06 02:14 PM
Field Original Value New Value
Assignee Graham Dumpleton [ grahamd ]
Graham Dumpleton made changes - 28/Feb/06 06:29 PM
Status Open [ 1 ] In Progress [ 3 ]
Graham Dumpleton made changes - 08/Mar/06 06:51 PM
Attachment MP109_20060308_grahamd_1.diff [ 12323922 ]
Graham Dumpleton made changes - 10/Mar/06 06:40 PM
Status In Progress [ 3 ] Open [ 1 ]
Graham Dumpleton made changes - 13/Aug/06 08:01 AM
Fix Version/s 3.3 [ 12310101 ]
Graham Dumpleton made changes - 08/Oct/06 07:29 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Graham Dumpleton made changes - 05/Apr/07 11:31 AM
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Graham Dumpleton made changes - 11/May/07 05:10 AM
Fix Version/s 3.3.1 [ 12312496 ]