Bug 50339 - mod_jk parsing error if workers.properties contains whitespaces
Summary: mod_jk parsing error if workers.properties contains whitespaces
Status: RESOLVED FIXED
Alias: None
Product: Tomcat Connectors
Classification: Unclassified
Component: mod_jk (show other bugs)
Version: unspecified
Hardware: HP Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-25 11:17 UTC by Frank
Modified: 2014-02-17 13:52 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank 2010-11-25 11:17:51 UTC
I built tomcat-connectors-1.2.31 for httpd-2.2.17, but mod_jk logged a lot of configuration errors, and only removing whitespaces from the beginning of all lines in workers.properties solved it.


My workers properties looked like this:

### Templates ###
  worker.tpl2.type=ajp13
  worker.tpl2.lbfactor=100
  worker.tpl2.fail_on_status=500,503
  worker.tpl2.socket_timeout=0
  worker.tpl2.connect_timeout=50000
  worker.tpl2.connection_pool_size=4

And the mod_jk.log said:
[Thu Nov 25 16:02:54 2010] [8081:140330511210240] [debug] jk_map_read_property::jk_map.c (491): Adding property 'worker.tpl2.lbfactor' with value '000' to map.
[Thu Nov 25 16:02:54 2010] [8081:140330511210240] [error] jk_map_validate_property::jk_map.c (404): The attribute 'worker.tpl2.socket_tioeout' is not supported - please check the documentation for the supported attributes.

As you can see the value for lbfactor should be "100", but "000" was logged, and "socket_timeout" is written correctly in the config file, but the log says "socket_tioeout"
I commented out these lines just to see what happens, but that just made it complain about different values a few lines below.

Removing all whitespaces from the beginning of the lines solved it:
[Thu Nov 25 16:27:36 2010] [8453:139761970366208] [debug] jk_map_read_property::jk_map.c (491): Adding property 'worker.tpl2.socket_timeout' with value '0' to map.


There also was an Ubuntu bug filed for that problem, but because I built the module myself and did not use distribution packages, it seems that the error is in mod_jk itself.

Cheers,
Frank
Comment 1 Frank 2010-11-25 11:21:28 UTC
Forgot the link to the Ubuntu Launchpad bug report:
https://bugs.launchpad.net/ubuntu/+source/libapache-mod-jk/+bug/592576
Comment 2 Rainer Jung 2010-11-29 12:07:58 UTC
Can you please try the following patch:

Index: common/jk_map.c
===================================================================
--- common/jk_map.c     (revision 1032021)
+++ common/jk_map.c     (working copy)
@@ -630,6 +630,7 @@
 static size_t trim(char *s)
 {
     size_t i;
+    size_t off;

     /* check for empty strings */
     if (!(i = strlen(s)))
@@ -646,7 +647,10 @@
          isspace((int)((unsigned char)s[i])); i++);

     if (i > 0) {
-        strcpy(s, &s[i]);
+        for (off = i; '\0' != s[i]; i++); {
+            s[i - off] = s[i];
+        }
+        s[i - off] = s[i];
     }

     return strlen(s);

Thanks!

Rainer
Comment 3 Frank 2010-11-30 06:23:03 UTC
(In reply to comment #2)

Hi,

thanks for your answer, but I'm afraid the patch does not completely solve the problem.
The parser doesn't read any wrong values like "socket_tioeout" anymore, but it fails to read some values at all:

workers.properties looks like this:
### Templates ###
## Template 1
  worker.tpl1.method=Busyness
  worker.tpl1.sticky_session=True
  worker.tpl1.recover_time=20

## Template 2
  worker.tpl2.type=ajp13
  worker.tpl2.lbfactor=100
  worker.tpl2.fail_on_status=500,503
  worker.tpl2.socket_timeout=0
  worker.tpl2.connect_timeout=50000
  worker.tpl2.connection_pool_size=4

### /Templates ###
...
worker.list=lb_www.domain.tld
worker.lb_www.domain.tld.maintain=20
worker.lb_www.domain.tld.type=lb
worker.lb_www.domain.tld.balance_workers=worker1
worker.lb_www.domain.tld.reference=worker.tpl1

## Set properties for worker1 (ajp13)
worker.worker1.reference=worker.tpl2
worker.worker1.host=10.0.0.1
worker.worker1.port=9001
worker.worker1.route=123

The template entries are indented by 2 spaces, the worker entries are not!
That's a formatting error I made, and haven't discovered until yet (the file's got 939 lines ...).
All other worker entries are indented just like the templates.

But when the file looks like this, I get the error:
[Tue Nov 30 12:13:50 2010] [28294:140392364185344] [debug] jk_map_resolve_references::jk_map.c (816): Copying values from worker.tpl1. to worker.lb_www.domain.tld.
[Tue Nov 30 12:13:50 2010] [28294:140392364185344] [error] jk_map_inherit_properties::jk_map.c (882): Reference 'worker.tpl1.' not found

So, it can't read the line that references the template.
When I indent the worker entries by 2 spaces too, everything is fine.
Also when I remove the spaces in front of the template lines, it works.
But if there is a mixed use of spaces and no spaces, the parser fails.

It's no problem to fix my config file at all, but it's really hard to find an error like that.
Comment 4 Rainer Jung 2010-12-05 09:47:51 UTC
Fixed in r1042364.

The patch provided in comment #2 had a bug (superfluous semicolon prevented it from working). Please use the final fix which was applied.

Will be part of 1.2.32.
Comment 5 Frank 2010-12-07 07:40:27 UTC
Yes, that seems to work.
Thanks a lot, guys!

Cheers,
Frank
Comment 6 LiuYan 刘研 2011-06-02 06:42:40 UTC
Same error when parsing uriworkermap.properties (Fedora 15 x86_64, jk-1.2.31 x86_64).

[2011-06-02 14:14:39.676 +0800 Thu] [3441:140715468376096] [debug] jk_map_read_property::jk_map.c (491): Adding property '/*' with value 'localhsst' to map.
...
[2011-06-02 14:14:39.680 +0800 Thu] [3441:140715468376096] [trace] uri_worker_map_ext::jk_uri_worker_map.c (497): enter
[2011-06-02 14:14:39.680 +0800 Thu] [3441:140715468376096] [trace] wc_get_worker_for_name::jk_worker.c (106): enter
[2011-06-02 14:14:39.680 +0800 Thu] [3441:140715468376096] [debug] wc_get_worker_for_name::jk_worker.c (116): did not find a worker localhsst
[2011-06-02 14:14:39.680 +0800 Thu] [3441:140715468376096] [trace] wc_get_worker_for_name::jk_worker.c (118): exit
[2011-06-02 14:14:39.680 +0800 Thu] [3441:140715468376096] [error] uri_worker_map_ext::jk_uri_worker_map.c (506): Could not find worker with name 'localhsst' in uri map post processing.

Thanks for fixup!