Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change 
notification.

The following page has been changed by MarcMongenet:
http://wiki.apache.org/httpd/ModuleLife

The comment on the change is:
Problem with apr_pool_userdata_set if module is installed before a restart

------------------------------------------------------------------------------
+ HTTPd start-up phase:
+  * First execution "configuration check"
-  * The module is dynamically loaded in the single-process single-thread 
server, that is still running as root if it was started as root.
+   * The module is dynamically loaded in the single-process single-thread 
server, that is still running as root if it was started as root.
-  * The configuration is parsed, but just to check that it is valid (sanity 
check).
+   * The configuration is parsed, but just to check that it is valid (sanity 
check).
-  * The module post_init hook is called for the 1st time in the sanity check.
+   * The module post_init hook is called for the 1st time in the sanity check.
-  * Depending on platform, the module is completely unloaded. It means that 
global and static variables are reset. This also means any cleanups left 
pointing into the module against the process pool will go boom on exit.
+   * Depending on platform, the module is then completely unloaded. It means 
that global and static variables are reset. This also means any cleanups left 
pointing into the module against the process pool will go boom on exit.
+  * Second execution "live"
+   * The module is loaded again if necessary.
-  * The configuration is parsed again, for real this time.
+   * The configuration is parsed again, for real this time.
-  * The module post_init hook is called for the 2nd time.
+   * The module post_init hook is called for the 2nd time.
-  * Children processes are started, they may be forked (Unix) or spawned 
(Windows).
+   * Children processes are started. They may be forked (Unix) or spawned 
(Windows).
-  * The pre_init/post_init hooks are never called in the forked (Unix) child 
process, see the child_init hook instead.
+   * The pre_init/post_init hooks are never called in the forked (Unix) child 
process, see the child_init hook instead.
+   * If the children are spawned (as on Windows), they repeat the whole 
startup, and the post_config hook is called exactly twice again in the children 
(and never a third time on graceful restart).
+ 
+ HTTPd restart:
-  * On graceful restart, the module is unloaded and reloaded/init, and the 
post_config hook is called (still in the parent process) once again.
+  * On graceful restart, the module is unloaded and reloaded/init, and the 
post_config hook is called (still in the parent process) once, not twice.
-  * If the children are spawned (as on Windows), they repeat the whole 
startup, and the post_config hook is called exactly twice again in the children 
(and never a third time on graceful restart).  A new spawned child process is 
created by the parent upon a graceful restart.
+  * On Windows, a new spawned child process is created by the parent upon a 
graceful restart.
   * During a graceful restart, new children processes may be running on the 
new configuration while old children on the old configuration are still serving 
out their requests.
  
  == 1st and next post_config hook calls ==
- If we want to create mutexes, shared memory... only once, we have to execute 
the post_config hook body only once, and we have to set a flag on 1st execution 
and read it on 2nd.
+ A common hack to execute the post_config hook body only once is to set a flag 
on 1st execution and exit. On 2nd execution, the flag is retrieved and module 
initialization is performed. This hack uses the apr_pool_userdata_set and 
apr_pool_userdata_get functions to saves the flag in memory managed by the 
process pool.
  
   * Example from http://www.codemass.com/mod_shm_counter/
   * See also http://www.clove.org/~aaron/presentations/apachecon2002/
@@ -47, +54 @@

  
      /* If we made it this far, we can safely initialize the module */}}}
  
+ A problem with this hack exists when a module is installed while the server 
is running, and the server is just restarted to load the module. In this case, 
the post_config hook is executed once after restart and  will only set the 
flag. Module initialization will not be performed, and when child_init and 
other hooks are called, bad things may happen.
+ 
  === post_config hook call by children processes ===
  On WinNT MPM, the post_config hook is also called by the children processes.
  

Reply via email to