I've been trying out the new version of mod_jk (1.2.15) I've been working on upgrading our mod_jk from 1.2.9 to 1.2.15. (We use mod_jk primarily on Linux, in conjunction with apache 2.0.53 and tomcat 5.5.15). During testing, I noticed several cases of JkMount mappings going to the wrong set of workers. By `wrong', I mean `not the same workers as 1.2.9 would have chosen'; this behavior is reproducible with both the apache 1.3 and 2.0 versions of mod_jk Here is an example: Given JkMount directives: JkMount /k/* worker_k JkMount /s/* worker_s JkMount /m/* worker_m JkMount /h/* worker_h JkMount /*.jsp worker_default These mount points effectively represent 5 different applications under a single VirtualHost; and they're handled by 5 different groups of tomcats. I'll make a request for the uri "/this-uri-wont-match". Here is the portion of JkLogFile that attempts matching: [Tue Mar 07 16:20:40 2006] [16809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (449): Attempting to map URI '/this-uri-wont-match' from 5 maps [Tue Mar 07 16:20:40 2006] [16809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/*.jsp' [Tue Mar 07 16:20:40 2006] [16809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/k/*' [Tue Mar 07 16:20:40 2006] [16809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/s/*' [Tue Mar 07 16:20:40 2006] [16809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/m/*' [Tue Mar 07 16:20:40 2006] [16809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/h/*' I see that the code is attempting a `longest-pattern-first' match. However, the side effect of this is uri's like /m/some.jsp /h/some-other.jsp /s/yet-another.jsp .... become unreachable. Because mod_jk 1.2.15 uses pattern length, and not *configuration file* order, there are circumstances where it will never match the desired servlet container. Commenting out the call to worker_qsort() (line 297 of jk_uri_worker_map.c -- diff attached) makes the issue go away. Would it be possible to go back to matching based on configuration file order?
Created attachment 17844 [details] Patch to jk_uri_worker_map.c
I see what mod_jk is doing in attempting to match the longest uri pattern first. The Servlet specification 2.4 (section SRV.11.1) says The container will recursively try tomatch the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the / character as a path separator. The longest match determines the servlet selected. This definitely favors a longest match. However, I think it also implies that 'longest' means 'most uri path elements'. I'd like to submit a patch that brings mod_jk closer to this behavior. I'll attach the patch to this issue. Below are some JkLogFile examples to demonstrate what the patch does. * * * For what follows, I've set up an apache configuration with this list of workers defined: JkMount /*.jsp worker_default JkMount /a/* worker_a JkMount /a/1/* worker_a1 JkMount /a/1/2/* worker_a12 JkMount /golly-gee-batman/* worker_golly This is the order in which the JkMount directives appear in the httpd configuration -- the goal is to verify that `most path elements' gets preference. The first two samples of log output show a stock mod_jk 1.2.15; subsequent examples show a patched mod_jk 1.2.15. * * * # (unpatched mod_jk-1.2.15) # # Here, we submit a non-matching URI, just to see the iteration # order that mod_jk will use when attempting to locate a worker for # the request. [Wed Mar 08 10:49:22 2006] [18652:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (449): Attempting to map URI '/not-found' from 5 maps [Wed Mar 08 10:49:22 2006] [18652:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/golly-gee-batman/*' [Wed Mar 08 10:49:22 2006] [18652:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 10:49:22 2006] [18652:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/*.jsp' [Wed Mar 08 10:49:22 2006] [18652:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/a/1/*' [Wed Mar 08 10:49:22 2006] [18652:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/a/*' # (unpatched mod_jk-1.2.15) # # Here, we have a request for /a/1/foo.jsp. Log entries below show # thie request being mapped to '/*.jsp', not '/a/1/*' # [Wed Mar 08 10:52:56 2006] [18653:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (449): Attempting to map URI '/a/1/foo.jsp' from 5 maps [Wed Mar 08 10:52:56 2006] [18653:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/golly-gee-batman/*' [Wed Mar 08 10:52:56 2006] [18653:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 10:52:56 2006] [18653:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (461): Attempting to map context URI '/*.jsp' [Wed Mar 08 10:52:56 2006] [18653:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (475): Found a wildchar match worker_default -> /*.jsp * * * # (patched mod_jk-1.2.15) # # Here is the same "/not-found" request, made against mod_jk-1.2.15, # with the submitted patch. Note that the matching order reflects # the number of uri path elements in the JkMount directive. # [Wed Mar 08 11:31:15 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (487): Attempting to map URI '/not-found' from 5 maps [Wed Mar 08 11:31:15 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 11:31:15 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/*' [Wed Mar 08 11:31:15 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/golly-gee-batman/*' [Wed Mar 08 11:31:15 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/*' [Wed Mar 08 11:31:15 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/*.jsp' # (patched mod_jk-1.2.15) # # Request for '/a/1/2/foo.jsp' # [Wed Mar 08 11:32:29 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (487): Attempting to map URI '/a/1/2/foo.jsp' from 5 maps [Wed Mar 08 11:32:29 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 11:32:29 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (513): Found a wildchar match worker_a12 -> /a/1/2/* # (patched mod_jk-1.2.15) # # Request for '/a/1/foo.jsp' # # [Wed Mar 08 11:33:20 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (487): Attempting to map URI '/a/1/foo.jsp' from 5 maps [Wed Mar 08 11:33:20 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 11:33:20 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/*' [Wed Mar 08 11:33:20 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (513): Found a wildchar match worker_a1 -> /a/1/* # (patched mod_jk-1.2.15) # # Request for '/a/foo.jsp' # # [Wed Mar 08 11:34:01 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (487): Attempting to map URI '/a/foo.jsp' from 5 maps [Wed Mar 08 11:34:01 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 11:34:01 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/*' [Wed Mar 08 11:34:01 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/golly-gee-batman/*' [Wed Mar 08 11:34:01 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/*' [Wed Mar 08 11:34:01 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (513): Found a wildchar match worker_a -> /a/* # (patched mod_jk-1.2.15) # # Request for '/golly-gee-batman/foo.jsp' # # [Wed Mar 08 11:34:53 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (487): Attempting to map URI '/golly-gee-batman/foo.jsp' from 5 maps [Wed Mar 08 11:34:53 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 11:34:53 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/*' [Wed Mar 08 11:34:53 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/golly-gee-batman/*' [Wed Mar 08 11:34:53 2006] [20808:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (513): Found a wildchar match worker_golly -> /golly-gee-batman/* # (patched mod_jk-1.2.15) # # Request for '/foo.jsp' # [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (487): Attempting to map URI '/foo.jsp' from 5 maps [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/2/*' [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/1/*' [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/golly-gee-batman/*' [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/a/*' [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (499): Attempting to map context URI '/*.jsp' [Wed Mar 08 11:35:27 2006] [20809:0000] [debug] map_uri_to_worker::jk_uri_worker_map.c (513): Found a wildchar match worker_default -> /*.jsp
Created attachment 17848 [details] jk_uri_worker_map.c patch to order matching based on # of uri path elements
Commited. Thanks!