Hi,

In order for URLs proxied using RewriteRule with the P-flag to benefit from 
proxy worker connection pools, I have experimented a modification of mod_proxy 
that implicitly creates a new worker whenever no worker is found for a request. 
The patch below is against proxy_util.c of Apache 2.2.4.

The code somehow seems to work as intended: on the first occurence of a URL 
rewritten to proxy: a new worker is created, a connection is opened and added 
to the worker resource pool. On the second occurence of the URL previously 
proxied, it gets the previously created worker and reuses an existing 
connection to the backend.

However I enventually get the following error:

[Fri Aug 31 15:32:19 2007] [emerg] (os 0x001ebf50)Unrecognized resolver error: 
apr_proc_mutex_lock failed. Attempting to shutdown process gracefully.

It seems like the server does not appreciate the initialisation of a new worker 
during request processing...

Some questions:
1. Has initialising new workers this way been discussed among the developers 
and rejected for some reason ?
2. Is what I propose feasible ?
3. Any idea about how to avoid the above mentioned error or otherwise other 
suggestions regarding the implementation of this feature?

Thanks
-ascs


*** proxy_util.c.orig   Tue Dec 19 22:56:16 2006
--- proxy_util.c        Fri Aug 31 14:26:03 2007
***************
*** 20,25 ****
--- 20,35 ----
  #include "scoreboard.h"
  #include "apr_version.h"
  
+ #define PROXY_COPY_CONF_PARAMS(w, c) \
+     do {                             \
+         (w)->timeout              = (c)->timeout;               \
+         (w)->timeout_set          = (c)->timeout_set;           \
+         (w)->recv_buffer_size     = (c)->recv_buffer_size;      \
+         (w)->recv_buffer_size_set = (c)->recv_buffer_size_set;  \
+         (w)->io_buffer_size       = (c)->io_buffer_size;        \
+         (w)->io_buffer_size_set   = (c)->io_buffer_size_set;    \
+     } while (0)
+ 
  #if APR_HAVE_UNISTD_H
  #include <unistd.h>         /* for getpid() */
  #endif
***************
*** 1394,1407 ****
          }
          else if (r->proxyreq == PROXYREQ_REVERSE) {
              if (conf->reverse) {
-                 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
-                               "proxy: *: found reverse proxy worker for %s",
-                                *url);
                  *balancer = NULL;
!                 *worker = conf->reverse;
                  access_status = OK;
              }
!         }
      }
      else if (access_status == DECLINED && *balancer != NULL) {
          /* All the workers are busy */
--- 1404,1434 ----
          }
          else if (r->proxyreq == PROXYREQ_REVERSE) {
              if (conf->reverse) {
                  *balancer = NULL;
!                 const char *err = ap_proxy_add_worker(worker, conf->pool, 
conf, *url);
!               if (err) {
!                  ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
!                                  "proxy: unable to add new reverse proxy 
worker for %s - %s",
!                                  *url, err);
!                  ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
!                                  "proxy: *: found reverse proxy worker for 
%s",
!                                  *url);
!                    *worker = conf->reverse;
!               }
!               else
!               {
!                  PROXY_COPY_CONF_PARAMS((proxy_worker *) *worker, 
(proxy_server_conf *) conf);
! 
!                  ap_proxy_initialize_worker_share(conf, *worker, r->server);
!                  ap_proxy_initialize_worker(*worker, r->server);
!                  /* Do not disable worker in case of errors */
!                  (*worker)->s->status |= PROXY_WORKER_IGNORE_ERRORS;
!                  /* Disable address cache for generic reverse worker */
!                  (*worker)->is_address_reusable = 1;
!               }
                  access_status = OK;
              }
!       }
      }
      else if (access_status == DECLINED && *balancer != NULL) {
          /* All the workers are busy */

Reply via email to