Bug 45076 - pre_config hooks not called in order
Summary: pre_config hooks not called in order
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.5-HEAD
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2008-05-26 02:48 UTC by MENEAULT
Modified: 2012-02-04 20:55 UTC (History)
0 users



Attachments
pre_config hooks patch for trunk (1.43 KB, patch)
2008-05-26 02:48 UTC, MENEAULT
Details | Diff
pre_config hooks patch for 2.2.8 (1.34 KB, patch)
2008-05-26 03:23 UTC, MENEAULT
Details | Diff
pre_config hooks patch for 2.2.10 (1.34 KB, patch)
2008-11-08 12:47 UTC, MENEAULT
Details | Diff
fix order for pre_config hooks as well as hooks that are registered later (1.46 KB, patch)
2011-10-07 18:07 UTC, Torsten F
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description MENEAULT 2008-05-26 02:48:00 UTC
Created attachment 22000 [details]
pre_config hooks patch for trunk

Apparently pre_config hooks are not ordered when ap_run_pre_config is called.
I noticed and verified one issue and I noticed another one (syntactically only) while reading through the code.

First issue (verified):
While during the first configuration pass pre_config hooks seem to be ordered for prelinked modules during the second one hooks are not ordered (i.e. not in the order specified by APR_HOOK_FIRST...defines).
Fix:
apr_hook_sort_all is called too late during second and further configuration passes.
It needs to be called before ap_run_pre_config (l.734 of server/main.c).

Second issue (only noticed while reading the code):
pre_config hooks might not be ordered for dynamically loaded modules even during first configuration pass.
Fix:
apr_hook_sort_all needs to be called before ap_run_pre_config (l.656 of server/main.c)

I was working on 2.2.3 which suffer from these issues. I checked 2.2.8 and trunk which still suffer these issues.

Please see attached a patch for trunk to fix these issues.

I compiled the server and checked that my patch correct the first issue (I don't use dynamically loaded modules).

My patch shouldn't provoke any regression however I don't know why apr_hook_sort_all was called so late. Was there any reason for that?

The only assumption I make is that hooks have to be hooked during register hooks during module initialization or otherwise apr_hook_sort_all should be manually called after registering a hook (as mod_cgid does).
Comment 1 MENEAULT 2008-05-26 03:23:00 UTC
Created attachment 22001 [details]
pre_config hooks patch for 2.2.8

Patch for the 2.2.8 version (just in case)
Comment 2 MENEAULT 2008-11-08 12:47:08 UTC
Created attachment 22844 [details]
pre_config hooks patch for 2.2.10

Adding patch for 2.2.10 as requested by Bruce Mills (Apache dev mailing list, thread: ap_run_pre_config issue).
Note: I didn't test it but it should work as well as older patches.
Comment 3 Stefan Fritsch 2011-06-15 22:32:29 UTC
This is already fixed in trunk and has been proposed for 2.2.20
Comment 4 MENEAULT 2011-06-16 06:56:58 UTC
I checked trunk revision 1032002; the patch to server/main.c is the same as mine so it should effectively be fixed in trunk.

Thanks.
Comment 5 Torsten F 2011-10-07 18:01:29 UTC
Reopen the bug because the fix introduces a very similar bug.

Modperl allows to write modules in Perl. Those modules can also register 
hooks. The earliest point in time when that may happen is in 
ap_process_config_tree() because there are config statements that 
influence certain parameters of the perl interpreter. So, we have to 
process those statements prior to starting the interpreter. But only the 
perl interpreter knows which modules to load. Those modules then can 
install hooks. But with revision 1162854 these hooks are called out of 
order.
Comment 6 Torsten F 2011-10-07 18:07:58 UTC
Created attachment 27730 [details]
fix order for pre_config hooks as well as hooks that are registered later

The patch is to be applied on top of revision 1162854 which has MENEAULT's patch applied. In addition to calling apr_hook_sort_all() at the new location it calls it again when ap_process_config_tree() is done.
Comment 7 Stefan Fritsch 2011-10-08 07:16:58 UTC
committed in trunk as r1180325
Comment 8 Stefan Fritsch 2012-02-04 20:55:27 UTC
fixed in 2.2.22