Our rewrite rules were
becoming difficult to manage here, so we decided to instead use a python script
and config file to easily edit and add rewrite rules. However, when we implemented
this change, we saw what appears to be a synchronization issue. I’ll try
to sum up what we have in code. Using rewritemap and
rewritelock, we made the following changes to our conf file: In httpd.conf: RewriteLock
/tmp/rewritelockfile.lock In vhost: RewriteEngine On RewriteLogLevel 1 RewriteLog
/weblog/httpd/logfile RewriteMap rewritepy
prg:/bin/rewriter.py RewriteRule .*
${rewritepy:%{THE_REQUEST} [L] For the sake of not
including too much python code, we will sum up /bin/rewriter.py as having: while True: request
= sys.stdin.readline() results
= get_redirect(request) sys.stdout.write(results
+ "\n") sys.stdout.flush() In a low traffic
environment, there is no problem, but when many users are hitting this at the
same time, we see users getting each other’s redirects. For example,
user 1 asks for page a and user 2 asks for page b, but user 1 gets page b and
user 2 gets page a. We have tested quite a bit
with creating the file ahead of time using varying permissions to see if any
errors or warnings appeared in the error log but saw nothing. We set the
permissions obviously wrong on several occasions, but apache didn't seem to notice
or care. We have also run strace
against the process and cannot see where apache even attempts to create or
access the file when a request is made. We have tested with various
versions of apache: Centos
4.7/Apache/2.0.52/httpd-2.0.52-41.ent.centos4 Centos 5/Server version:
Apache/2.2.3/httpd-2.2.3-11.el5_1.centos.3 Ubuntu
8.04/Apache/2.2.8(Ubuntu)/apache2.2-common 2.2.8-1ubuntu0.3 And we see the same results
each time … does not appear to access the file. We can confirm that rewrite
itself is working and also can see the extra semaphore being created via ipcs
when we have RewriteLock turned on. It was our understanding
that the RewriteLock was supposed to prevent synchronization issues such as
this. Any help would be appreciated. |