Skip to content

Commit

Permalink
Child processes would keep crashing if mod_wsgi was loaded for the fi…
Browse files Browse the repository at this point in the history
…rst time as side effect of graceful restart. #94
  • Loading branch information
GrahamDumpleton committed Oct 4, 2015
1 parent 1abae88 commit 3aef8bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/release-notes/version-4.4.15.rst
Expand Up @@ -17,3 +17,12 @@ Bugs Fixed
using the ``WSGIPythonPath`` directive, or the ``python-path`` option to
``WSGIDaemonProcess``, it was failing under Python 3 due to incorrect
logging. It was therefore only possible to add a single directory.

2. If Apache was already running when the mod_wsgi module was enabled or
otherwise configured to be loaded, and then an Apache graceful restart was
done so that it would be loaded for the first time, all child processes
would crash when starting up and would keep crashing, requiring Apache be
shutdown. This would occur as Python initialisation was not being performed
correctly in this specific case where mod_wsgi was loaded when Apache was
already running and a graceful restart, rather than a normal restart was
done.
28 changes: 26 additions & 2 deletions src/server/mod_wsgi.c
Expand Up @@ -12299,16 +12299,40 @@ static int wsgi_hook_init(apr_pool_t *pconf, apr_pool_t *ptemp,
* Init function gets called twice during startup, we only
* need to actually do anything on the second time it is
* called. This avoids unecessarily initialising and then
* destroying Python for no reason.
* destroying Python for no reason. We also though have to
* deal with a special case when a graceful restart is done.
* For that we are only called once, which is generally okay
* as the 'wsgi_init' key will be set from initial start up
* of the server. The exception to this is where the module
* is only loaded into Apache when the server is already
* running. In this case we have to detect that it is not
* the initial startup, but a subsequent restart. We can do
* this by looking at whether the scoreboard has been
* initialised yet. That is probably enough, but to be safe,
* also check what generation it is.
*/

userdata_key = "wsgi_init";

apr_pool_userdata_get(&data, userdata_key, s->process->pool);

if (!data) {
apr_pool_userdata_set((const void *)1, userdata_key,
apr_pool_cleanup_null, s->process->pool);
return OK;

/*
* Check for the special case of a graceful restart and
* the module being loaded for the first time. In this
* case we still go onto perform initialisation as the
* initialisation routine for the module will not be
* called a second time.
*/

if (!ap_scoreboard_image ||
ap_get_scoreboard_global()->running_generation == 0) {

return OK;
}
}

/* Setup module version information. */
Expand Down

0 comments on commit 3aef8bf

Please sign in to comment.