85cb4d
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
85cb4d
index 57cc92f..fbbd508 100644
85cb4d
--- a/modules/proxy/mod_proxy.h
85cb4d
+++ b/modules/proxy/mod_proxy.h
85cb4d
@@ -288,12 +288,15 @@ typedef struct {
85cb4d
 
85cb4d
 /* Connection pool */
85cb4d
 struct proxy_conn_pool {
85cb4d
-    apr_pool_t     *pool;   /* The pool used in constructor and destructor calls */
85cb4d
-    apr_sockaddr_t *addr;   /* Preparsed remote address info */
85cb4d
-    apr_reslist_t  *res;    /* Connection resource list */
85cb4d
-    proxy_conn_rec *conn;   /* Single connection for prefork mpm */
85cb4d
+    apr_pool_t     *pool;     /* The pool used in constructor and destructor calls */
85cb4d
+    apr_sockaddr_t *addr;     /* Preparsed remote address info */
85cb4d
+    apr_reslist_t  *res;      /* Connection resource list */
85cb4d
+    proxy_conn_rec *conn;     /* Single connection for prefork mpm */
85cb4d
+    apr_pool_t     *dns_pool; /* The pool used for worker scoped DNS resolutions */
85cb4d
 };
85cb4d
 
85cb4d
+#define AP_VOLATILIZE_T(T, x) (*(T volatile *)&(x))
85cb4d
+
85cb4d
 /* worker status bits */
85cb4d
 /*
85cb4d
  * NOTE: Keep up-to-date w/ proxy_wstat_tbl[]
85cb4d
@@ -475,7 +478,9 @@ struct proxy_worker {
85cb4d
     proxy_conn_pool     *cp;    /* Connection pool to use */
85cb4d
     proxy_worker_shared   *s;   /* Shared data */
85cb4d
     proxy_balancer  *balancer;  /* which balancer am I in? */
85cb4d
+#if APR_HAS_THREADS
85cb4d
     apr_thread_mutex_t  *tmutex; /* Thread lock for updating address cache */
85cb4d
+#endif
85cb4d
     void            *context;   /* general purpose storage */
85cb4d
     ap_conf_vector_t *section_config; /* <Proxy>-section wherein defined */
85cb4d
 };
85cb4d
@@ -534,7 +539,9 @@ struct proxy_balancer {
85cb4d
     apr_time_t      wupdated;    /* timestamp of last change to workers list */
85cb4d
     proxy_balancer_method *lbmethod;
85cb4d
     apr_global_mutex_t  *gmutex; /* global lock for updating list of workers */
85cb4d
+#if APR_HAS_THREADS
85cb4d
     apr_thread_mutex_t  *tmutex; /* Thread lock for updating shm */
85cb4d
+#endif
85cb4d
     proxy_server_conf *sconf;
85cb4d
     void            *context;    /* general purpose storage */
85cb4d
     proxy_balancer_shared *s;    /* Shared data */
85cb4d
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c
85cb4d
index c59f5e9..3a28038 100644
85cb4d
--- a/modules/proxy/mod_proxy_balancer.c
85cb4d
+++ b/modules/proxy/mod_proxy_balancer.c
85cb4d
@@ -346,23 +346,27 @@ static proxy_worker *find_best_worker(proxy_balancer *balancer,
85cb4d
     proxy_worker *candidate = NULL;
85cb4d
     apr_status_t rv;
85cb4d
 
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
85cb4d
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01163)
85cb4d
                       "%s: Lock failed for find_best_worker()",
85cb4d
                       balancer->s->name);
85cb4d
         return NULL;
85cb4d
     }
85cb4d
+#endif
85cb4d
 
85cb4d
     candidate = (*balancer->lbmethod->finder)(balancer, r);
85cb4d
 
85cb4d
     if (candidate)
85cb4d
         candidate->s->elected++;
85cb4d
 
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
85cb4d
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01164)
85cb4d
                       "%s: Unlock failed for find_best_worker()",
85cb4d
                       balancer->s->name);
85cb4d
     }
85cb4d
+#endif
85cb4d
 
85cb4d
     if (candidate == NULL) {
85cb4d
         /* All the workers are in error state or disabled.
85cb4d
@@ -492,11 +496,13 @@ static int proxy_balancer_pre_request(proxy_worker **worker,
85cb4d
     /* Step 2: Lock the LoadBalancer
85cb4d
      * XXX: perhaps we need the process lock here
85cb4d
      */
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
85cb4d
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166)
85cb4d
                       "%s: Lock failed for pre_request", (*balancer)->s->name);
85cb4d
         return DECLINED;
85cb4d
     }
85cb4d
+#endif
85cb4d
 
85cb4d
     /* Step 3: force recovery */
85cb4d
     force_recovery(*balancer, r->server);
85cb4d
@@ -557,20 +563,24 @@ static int proxy_balancer_pre_request(proxy_worker **worker,
85cb4d
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01167)
85cb4d
                           "%s: All workers are in error state for route (%s)",
85cb4d
                           (*balancer)->s->name, route);
85cb4d
+#if APR_HAS_THREADS
85cb4d
             if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
85cb4d
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01168)
85cb4d
                               "%s: Unlock failed for pre_request",
85cb4d
                               (*balancer)->s->name);
85cb4d
             }
85cb4d
+#endif
85cb4d
             return HTTP_SERVICE_UNAVAILABLE;
85cb4d
         }
85cb4d
     }
85cb4d
 
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
85cb4d
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01169)
85cb4d
                       "%s: Unlock failed for pre_request",
85cb4d
                       (*balancer)->s->name);
85cb4d
     }
85cb4d
+#endif
85cb4d
     if (!*worker) {
85cb4d
         runtime = find_best_worker(*balancer, r);
85cb4d
         if (!runtime) {
85cb4d
@@ -644,12 +654,14 @@ static int proxy_balancer_post_request(proxy_worker *worker,
85cb4d
 
85cb4d
     apr_status_t rv;
85cb4d
 
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
85cb4d
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01173)
85cb4d
                       "%s: Lock failed for post_request",
85cb4d
                       balancer->s->name);
85cb4d
         return HTTP_INTERNAL_SERVER_ERROR;
85cb4d
     }
85cb4d
+#endif
85cb4d
 
85cb4d
     if (!apr_is_empty_array(balancer->errstatuses)
85cb4d
         && !(worker->s->status & PROXY_WORKER_IGNORE_ERRORS)) {
85cb4d
@@ -681,11 +693,12 @@ static int proxy_balancer_post_request(proxy_worker *worker,
85cb4d
         worker->s->error_time = apr_time_now();
85cb4d
 
85cb4d
     }
85cb4d
-
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
85cb4d
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01175)
85cb4d
                       "%s: Unlock failed for post_request", balancer->s->name);
85cb4d
     }
85cb4d
+#endif
85cb4d
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176)
85cb4d
                   "proxy_balancer_post_request for (%s)", balancer->s->name);
85cb4d
 
85cb4d
@@ -945,7 +958,6 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
85cb4d
             PROXY_STRNCPY(balancer->s->sname, sname); /* We know this will succeed */
85cb4d
 
85cb4d
             balancer->max_workers = balancer->workers->nelts + balancer->growth;
85cb4d
-
85cb4d
             /* Create global mutex */
85cb4d
             rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
85cb4d
                                         balancer->s->sname, s, pconf, 0);
85cb4d
@@ -955,7 +967,6 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
85cb4d
                              balancer->s->sname);
85cb4d
                 return HTTP_INTERNAL_SERVER_ERROR;
85cb4d
             }
85cb4d
-
85cb4d
             apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
85cb4d
                                       apr_pool_cleanup_null);
85cb4d
 
85cb4d
@@ -1135,17 +1146,21 @@ static int balancer_handler(request_rec *r)
85cb4d
 
85cb4d
     balancer = (proxy_balancer *)conf->balancers->elts;
85cb4d
     for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
85cb4d
+#if APR_HAS_THREADS
85cb4d
         if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
85cb4d
             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01189)
85cb4d
                           "%s: Lock failed for balancer_handler",
85cb4d
                           balancer->s->name);
85cb4d
         }
85cb4d
+#endif
85cb4d
         ap_proxy_sync_balancer(balancer, r->server, conf);
85cb4d
+#if APR_HAS_THREADS
85cb4d
         if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
85cb4d
             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01190)
85cb4d
                           "%s: Unlock failed for balancer_handler",
85cb4d
                           balancer->s->name);
85cb4d
         }
85cb4d
+#endif
85cb4d
     }
85cb4d
 
85cb4d
     if (r->args && (r->method_number == M_GET)) {
85cb4d
@@ -1359,11 +1374,13 @@ static int balancer_handler(request_rec *r)
85cb4d
             proxy_worker *nworker;
85cb4d
             nworker = ap_proxy_get_worker(r->pool, bsel, conf, val);
85cb4d
             if (!nworker && storage->num_free_slots(bsel->wslot)) {
85cb4d
+#if APR_HAS_THREADS
85cb4d
                 if ((rv = PROXY_GLOBAL_LOCK(bsel)) != APR_SUCCESS) {
85cb4d
                     ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01194)
85cb4d
                                   "%s: Lock failed for adding worker",
85cb4d
                                   bsel->s->name);
85cb4d
                 }
85cb4d
+#endif
85cb4d
                 ret = ap_proxy_define_worker(conf->pool, &nworker, bsel, conf, val, 0);
85cb4d
                 if (!ret) {
85cb4d
                     unsigned int index;
85cb4d
@@ -1372,53 +1389,76 @@ static int balancer_handler(request_rec *r)
85cb4d
                     if ((rv = storage->grab(bsel->wslot, &index)) != APR_SUCCESS) {
85cb4d
                         ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01195)
85cb4d
                                       "worker slotmem_grab failed");
85cb4d
+#if APR_HAS_THREADS
85cb4d
                         if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
85cb4d
                             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01196)
85cb4d
                                           "%s: Unlock failed for adding worker",
85cb4d
                                           bsel->s->name);
85cb4d
                         }
85cb4d
+#endif
85cb4d
                         return HTTP_BAD_REQUEST;
85cb4d
                     }
85cb4d
                     if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) {
85cb4d
                         ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01197)
85cb4d
                                       "worker slotmem_dptr failed");
85cb4d
+#if APR_HAS_THREADS
85cb4d
                         if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
85cb4d
                             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01198)
85cb4d
                                           "%s: Unlock failed for adding worker",
85cb4d
                                           bsel->s->name);
85cb4d
                         }
85cb4d
+#endif
85cb4d
                         return HTTP_BAD_REQUEST;
85cb4d
                     }
85cb4d
                     if ((rv = ap_proxy_share_worker(nworker, shm, index)) != APR_SUCCESS) {
85cb4d
                         ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01199)
85cb4d
                                       "Cannot share worker");
85cb4d
+#if APR_HAS_THREADS
85cb4d
                         if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
85cb4d
                             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01200)
85cb4d
                                           "%s: Unlock failed for adding worker",
85cb4d
                                           bsel->s->name);
85cb4d
                         }
85cb4d
+#endif
85cb4d
                         return HTTP_BAD_REQUEST;
85cb4d
                     }
85cb4d
                     if ((rv = ap_proxy_initialize_worker(nworker, r->server, conf->pool)) != APR_SUCCESS) {
85cb4d
                         ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01201)
85cb4d
                                       "Cannot init worker");
85cb4d
+#if APR_HAS_THREADS
85cb4d
                         if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
85cb4d
                             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01202)
85cb4d
                                           "%s: Unlock failed for adding worker",
85cb4d
                                           bsel->s->name);
85cb4d
                         }
85cb4d
+#endif
85cb4d
                         return HTTP_BAD_REQUEST;
85cb4d
                     }
85cb4d
                     /* sync all timestamps */
85cb4d
                     bsel->wupdated = bsel->s->wupdated = nworker->s->updated = apr_time_now();
85cb4d
                     /* by default, all new workers are disabled */
85cb4d
                     ap_proxy_set_wstatus(PROXY_WORKER_DISABLED_FLAG, 1, nworker);
85cb4d
+                } else {
85cb4d
+                            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10163)
85cb4d
+                                  "%s: failed to add worker %s",
85cb4d
+                                  bsel->s->name, val);
85cb4d
+#if APR_HAS_THREADS
85cb4d
+                    PROXY_GLOBAL_UNLOCK(bsel);
85cb4d
+#endif
85cb4d
+                    return HTTP_BAD_REQUEST;
85cb4d
                 }
85cb4d
+#if APR_HAS_THREADS
85cb4d
                 if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
85cb4d
                     ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01203)
85cb4d
                                   "%s: Unlock failed for adding worker",
85cb4d
                                   bsel->s->name);
85cb4d
                 }
85cb4d
+#endif
85cb4d
+            } else {
85cb4d
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10164)
85cb4d
+                                  "%s: failed to add worker %s",
85cb4d
+                                  bsel->s->name, val);
85cb4d
+                return HTTP_BAD_REQUEST;
85cb4d
             }
85cb4d
 
85cb4d
         }
85cb4d
diff --git a/modules/proxy/mod_proxy_ftp.c b/modules/proxy/mod_proxy_ftp.c
85cb4d
index 5d9175e..5c4d641 100644
85cb4d
--- a/modules/proxy/mod_proxy_ftp.c
85cb4d
+++ b/modules/proxy/mod_proxy_ftp.c
85cb4d
@@ -979,8 +979,10 @@ static int proxy_ftp_handler(request_rec *r, proxy_worker *worker,
85cb4d
     apr_status_t rv;
85cb4d
     conn_rec *origin, *data = NULL;
85cb4d
     apr_status_t err = APR_SUCCESS;
85cb4d
+#if APR_HAS_THREADS
85cb4d
     apr_status_t uerr = APR_SUCCESS;
85cb4d
-    apr_bucket_brigade *bb = apr_brigade_create(p, c->bucket_alloc);
85cb4d
+#endif
85cb4d
+    apr_bucket_brigade *bb;
85cb4d
     char *buf, *connectname;
85cb4d
     apr_port_t connectport;
85cb4d
     char *ftpmessage = NULL;
85cb4d
@@ -1120,13 +1122,15 @@ static int proxy_ftp_handler(request_rec *r, proxy_worker *worker,
85cb4d
 
85cb4d
     if (worker->s->is_address_reusable) {
85cb4d
         if (!worker->cp->addr) {
85cb4d
+#if APR_HAS_THREADS
85cb4d
             if ((err = PROXY_THREAD_LOCK(worker->balancer)) != APR_SUCCESS) {
85cb4d
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, APLOGNO(01037) "lock");
85cb4d
                 return HTTP_INTERNAL_SERVER_ERROR;
85cb4d
             }
85cb4d
+#endif
85cb4d
         }
85cb4d
-        connect_addr = worker->cp->addr;
85cb4d
-        address_pool = worker->cp->pool;
85cb4d
+        connect_addr = AP_VOLATILIZE_T(apr_sockaddr_t *, worker->cp->addr);
85cb4d
+        address_pool = worker->cp->dns_pool;
85cb4d
     }
85cb4d
     else
85cb4d
         address_pool = r->pool;
85cb4d
@@ -1139,9 +1143,11 @@ static int proxy_ftp_handler(request_rec *r, proxy_worker *worker,
85cb4d
                                     address_pool);
85cb4d
     if (worker->s->is_address_reusable && !worker->cp->addr) {
85cb4d
         worker->cp->addr = connect_addr;
85cb4d
+#if APR_HAS_THREADS
85cb4d
         if ((uerr = PROXY_THREAD_UNLOCK(worker->balancer)) != APR_SUCCESS) {
85cb4d
             ap_log_rerror(APLOG_MARK, APLOG_ERR, uerr, r, APLOGNO(01038) "unlock");
85cb4d
         }
85cb4d
+#endif
85cb4d
     }
85cb4d
     /*
85cb4d
      * get all the possible IP addresses for the destname and loop through
85cb4d
@@ -1212,6 +1218,7 @@ static int proxy_ftp_handler(request_rec *r, proxy_worker *worker,
85cb4d
      * correct directory...
85cb4d
      */
85cb4d
 
85cb4d
+    bb = apr_brigade_create(p, c->bucket_alloc);
85cb4d
 
85cb4d
     /* possible results: */
85cb4d
     /* 120 Service ready in nnn minutes. */
85cb4d
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
85cb4d
index 2bfc8f0..7714b6c 100644
85cb4d
--- a/modules/proxy/proxy_util.c
85cb4d
+++ b/modules/proxy/proxy_util.c
85cb4d
@@ -1167,8 +1167,10 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p,
85cb4d
     lbmethod = ap_lookup_provider(PROXY_LBMETHOD, "byrequests", "0");
85cb4d
 
85cb4d
     (*balancer)->workers = apr_array_make(p, 5, sizeof(proxy_worker *));
85cb4d
+#if APR_HAS_THREADS
85cb4d
     (*balancer)->gmutex = NULL;
85cb4d
     (*balancer)->tmutex = NULL;
85cb4d
+#endif
85cb4d
     (*balancer)->lbmethod = lbmethod;
85cb4d
 
85cb4d
     if (do_malloc)
85cb4d
@@ -1257,7 +1259,9 @@ PROXY_DECLARE(apr_status_t) ap_proxy_share_balancer(proxy_balancer *balancer,
85cb4d
 
85cb4d
 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balancer, server_rec *s, apr_pool_t *p)
85cb4d
 {
85cb4d
+#if APR_HAS_THREADS
85cb4d
     apr_status_t rv = APR_SUCCESS;
85cb4d
+#endif
85cb4d
     ap_slotmem_provider_t *storage = balancer->storage;
85cb4d
     apr_size_t size;
85cb4d
     unsigned int num;
85cb4d
@@ -1297,6 +1301,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balance
85cb4d
     if (balancer->lbmethod && balancer->lbmethod->reset)
85cb4d
         balancer->lbmethod->reset(balancer, s);
85cb4d
 
85cb4d
+#if APR_HAS_THREADS
85cb4d
     if (balancer->tmutex == NULL) {
85cb4d
         rv = apr_thread_mutex_create(&(balancer->tmutex), APR_THREAD_MUTEX_DEFAULT, p);
85cb4d
         if (rv != APR_SUCCESS) {
85cb4d
@@ -1305,6 +1310,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balance
85cb4d
             return rv;
85cb4d
         }
85cb4d
     }
85cb4d
+#endif
85cb4d
     return APR_SUCCESS;
85cb4d
 }
85cb4d
 
85cb4d
@@ -1446,16 +1452,14 @@ static void socket_cleanup(proxy_conn_rec *conn)
85cb4d
 
85cb4d
 static apr_status_t conn_pool_cleanup(void *theworker)
85cb4d
 {
85cb4d
-    proxy_worker *worker = (proxy_worker *)theworker;
85cb4d
-    if (worker->cp->res) {
85cb4d
-        worker->cp->pool = NULL;
85cb4d
-    }
85cb4d
+    ((proxy_worker *)theworker)->cp = NULL;
85cb4d
     return APR_SUCCESS;
85cb4d
 }
85cb4d
 
85cb4d
 static void init_conn_pool(apr_pool_t *p, proxy_worker *worker)
85cb4d
 {
85cb4d
     apr_pool_t *pool;
85cb4d
+    apr_pool_t *dns_pool;
85cb4d
     proxy_conn_pool *cp;
85cb4d
 
85cb4d
     /*
85cb4d
@@ -1466,12 +1470,21 @@ static void init_conn_pool(apr_pool_t *p, proxy_worker *worker)
85cb4d
      */
85cb4d
     apr_pool_create(&pool, p);
85cb4d
     apr_pool_tag(pool, "proxy_worker_cp");
85cb4d
+    /*
85cb4d
+     * Create a subpool of the connection pool for worker
85cb4d
+     * scoped DNS resolutions. This is needed to avoid race
85cb4d
+     * conditions in using the connection pool by multiple
85cb4d
+     * threads during ramp up.
85cb4d
+     */
85cb4d
+    apr_pool_create(&dns_pool, pool);
85cb4d
+    apr_pool_tag(dns_pool, "proxy_worker_dns");
85cb4d
     /*
85cb4d
      * Alloc from the same pool as worker.
85cb4d
      * proxy_conn_pool is permanently attached to the worker.
85cb4d
      */
85cb4d
     cp = (proxy_conn_pool *)apr_pcalloc(p, sizeof(proxy_conn_pool));
85cb4d
     cp->pool = pool;
85cb4d
+    cp->dns_pool = dns_pool;
85cb4d
     worker->cp = cp;
85cb4d
 }
85cb4d
 
85cb4d
@@ -1487,14 +1500,6 @@ static apr_status_t connection_cleanup(void *theconn)
85cb4d
     proxy_conn_rec *conn = (proxy_conn_rec *)theconn;
85cb4d
     proxy_worker *worker = conn->worker;
85cb4d
 
85cb4d
-    /*
85cb4d
-     * If the connection pool is NULL the worker
85cb4d
-     * cleanup has been run. Just return.
85cb4d
-     */
85cb4d
-    if (!worker->cp->pool) {
85cb4d
-        return APR_SUCCESS;
85cb4d
-    }
85cb4d
-
85cb4d
     if (conn->r) {
85cb4d
         apr_pool_destroy(conn->r->pool);
85cb4d
         conn->r = NULL;
85cb4d
@@ -1616,7 +1621,7 @@ static apr_status_t connection_destructor(void *resource, void *params,
85cb4d
     proxy_worker *worker = params;
85cb4d
 
85cb4d
     /* Destroy the pool only if not called from reslist_destroy */
85cb4d
-    if (worker->cp->pool) {
85cb4d
+    if (worker->cp) {
85cb4d
         proxy_conn_rec *conn = resource;
85cb4d
         apr_pool_destroy(conn->pool);
85cb4d
     }
85cb4d
@@ -1972,67 +1977,73 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
85cb4d
                      ap_proxy_worker_name(p, worker));
85cb4d
     }
85cb4d
     else {
85cb4d
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927)
85cb4d
-                     "initializing worker %s local",
85cb4d
-                     ap_proxy_worker_name(p, worker));
85cb4d
         apr_global_mutex_lock(proxy_mutex);
85cb4d
-        /* Now init local worker data */
85cb4d
-        if (worker->tmutex == NULL) {
85cb4d
-            rv = apr_thread_mutex_create(&(worker->tmutex), APR_THREAD_MUTEX_DEFAULT, p);
85cb4d
-            if (rv != APR_SUCCESS) {
85cb4d
-                ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00928)
85cb4d
-                             "can not create worker thread mutex");
85cb4d
+        /* Check again after we got the lock if we are still uninitialized */
85cb4d
+        if (!(AP_VOLATILIZE_T(unsigned int, worker->local_status) & PROXY_WORKER_INITIALIZED)) {
85cb4d
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927)
85cb4d
+                         "initializing worker %s local",
85cb4d
+                         ap_proxy_worker_name(p, worker));
85cb4d
+            /* Now init local worker data */
85cb4d
+#if APR_HAS_THREADS
85cb4d
+            if (worker->tmutex == NULL) {
85cb4d
+                rv = apr_thread_mutex_create(&(worker->tmutex), APR_THREAD_MUTEX_DEFAULT, p);
85cb4d
+                if (rv != APR_SUCCESS) {
85cb4d
+                    ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00928)
85cb4d
+                                 "can not create worker thread mutex");
85cb4d
+                    apr_global_mutex_unlock(proxy_mutex);
85cb4d
+                    return rv;
85cb4d
+                }
85cb4d
+            }
85cb4d
+#endif
85cb4d
+            if (worker->cp == NULL)
85cb4d
+                init_conn_pool(p, worker);
85cb4d
+            if (worker->cp == NULL) {
85cb4d
+                ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00929)
85cb4d
+                             "can not create connection pool");
85cb4d
                 apr_global_mutex_unlock(proxy_mutex);
85cb4d
-                return rv;
85cb4d
+                return APR_EGENERAL;
85cb4d
             }
85cb4d
-        }
85cb4d
-        if (worker->cp == NULL)
85cb4d
-            init_conn_pool(p, worker);
85cb4d
-        if (worker->cp == NULL) {
85cb4d
-            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00929)
85cb4d
-                         "can not create connection pool");
85cb4d
-            apr_global_mutex_unlock(proxy_mutex);
85cb4d
-            return APR_EGENERAL;
85cb4d
-        }
85cb4d
 
85cb4d
-        if (worker->s->hmax) {
85cb4d
-            rv = apr_reslist_create(&(worker->cp->res),
85cb4d
-                                    worker->s->min, worker->s->smax,
85cb4d
-                                    worker->s->hmax, worker->s->ttl,
85cb4d
-                                    connection_constructor, connection_destructor,
85cb4d
-                                    worker, worker->cp->pool);
85cb4d
+            if (worker->s->hmax) {
85cb4d
+                rv = apr_reslist_create(&(worker->cp->res),
85cb4d
+                                        worker->s->min, worker->s->smax,
85cb4d
+                                        worker->s->hmax, worker->s->ttl,
85cb4d
+                                        connection_constructor, connection_destructor,
85cb4d
+                                        worker, worker->cp->pool);
85cb4d
 
85cb4d
-            apr_pool_cleanup_register(worker->cp->pool, (void *)worker,
85cb4d
-                                      conn_pool_cleanup,
85cb4d
-                                      apr_pool_cleanup_null);
85cb4d
+                apr_pool_pre_cleanup_register(worker->cp->pool, worker,
85cb4d
+                                              conn_pool_cleanup);
85cb4d
 
85cb4d
-            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00930)
85cb4d
-                "initialized pool in child %" APR_PID_T_FMT " for (%s) min=%d max=%d smax=%d",
85cb4d
-                 getpid(), worker->s->hostname_ex, worker->s->min,
85cb4d
-                 worker->s->hmax, worker->s->smax);
85cb4d
+                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00930)
85cb4d
+                    "initialized pool in child %" APR_PID_T_FMT " for (%s) min=%d max=%d smax=%d",
85cb4d
+                     getpid(), worker->s->hostname_ex, worker->s->min,
85cb4d
+                     worker->s->hmax, worker->s->smax);
85cb4d
 
85cb4d
-            /* Set the acquire timeout */
85cb4d
-            if (rv == APR_SUCCESS && worker->s->acquire_set) {
85cb4d
-                apr_reslist_timeout_set(worker->cp->res, worker->s->acquire);
85cb4d
-            }
85cb4d
+                /* Set the acquire timeout */
85cb4d
+                if (rv == APR_SUCCESS && worker->s->acquire_set) {
85cb4d
+                    apr_reslist_timeout_set(worker->cp->res, worker->s->acquire);
85cb4d
+                }
85cb4d
 
85cb4d
-        }
85cb4d
-        else {
85cb4d
-            void *conn;
85cb4d
+            }
85cb4d
+            else {
85cb4d
+                void *conn;
85cb4d
 
85cb4d
-            rv = connection_constructor(&conn, worker, worker->cp->pool);
85cb4d
-            worker->cp->conn = conn;
85cb4d
+                rv = connection_constructor(&conn, worker, worker->cp->pool);
85cb4d
+                worker->cp->conn = conn;
85cb4d
 
85cb4d
-            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00931)
85cb4d
-                 "initialized single connection worker in child %" APR_PID_T_FMT " for (%s)",
85cb4d
-                 getpid(), worker->s->hostname_ex);
85cb4d
+                ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s, APLOGNO(00931)
85cb4d
+                     "initialized single connection worker in child %" APR_PID_T_FMT " for (%s)",
85cb4d
+                     getpid(), worker->s->hostname_ex);
85cb4d
+            }
85cb4d
+            if (rv == APR_SUCCESS) {
85cb4d
+                worker->local_status |= (PROXY_WORKER_INITIALIZED);
85cb4d
+            }
85cb4d
         }
85cb4d
         apr_global_mutex_unlock(proxy_mutex);
85cb4d
 
85cb4d
     }
85cb4d
     if (rv == APR_SUCCESS) {
85cb4d
         worker->s->status |= (PROXY_WORKER_INITIALIZED);
85cb4d
-        worker->local_status |= (PROXY_WORKER_INITIALIZED);
85cb4d
     }
85cb4d
     return rv;
85cb4d
 }
85cb4d
@@ -2292,13 +2303,13 @@ PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
85cb4d
     else {
85cb4d
         /* create the new connection if the previous was destroyed */
85cb4d
         if (!worker->cp->conn) {
85cb4d
-            connection_constructor((void **)conn, worker, worker->cp->pool);
85cb4d
+            rv = connection_constructor((void **)conn, worker, worker->cp->pool);
85cb4d
         }
85cb4d
         else {
85cb4d
             *conn = worker->cp->conn;
85cb4d
             worker->cp->conn = NULL;
85cb4d
+            rv = APR_SUCCESS;
85cb4d
         }
85cb4d
-        rv = APR_SUCCESS;
85cb4d
     }
85cb4d
 
85cb4d
     if (rv != APR_SUCCESS) {
85cb4d
@@ -2344,7 +2355,9 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
85cb4d
 {
85cb4d
     int server_port;
85cb4d
     apr_status_t err = APR_SUCCESS;
85cb4d
+#if APR_HAS_THREADS
85cb4d
     apr_status_t uerr = APR_SUCCESS;
85cb4d
+#endif
85cb4d
     const char *uds_path;
85cb4d
 
85cb4d
     /*
85cb4d
@@ -2481,25 +2494,39 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
85cb4d
              * we can reuse the address.
85cb4d
              */
85cb4d
             if (!worker->cp->addr) {
85cb4d
+#if APR_HAS_THREADS
85cb4d
                 if ((err = PROXY_THREAD_LOCK(worker)) != APR_SUCCESS) {
85cb4d
                     ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, APLOGNO(00945) "lock");
85cb4d
                     return HTTP_INTERNAL_SERVER_ERROR;
85cb4d
                 }
85cb4d
+#endif
85cb4d
 
85cb4d
                 /*
85cb4d
-                 * Worker can have the single constant backend address.
85cb4d
-                 * The single DNS lookup is used once per worker.
85cb4d
-                 * If dynamic change is needed then set the addr to NULL
85cb4d
-                 * inside dynamic config to force the lookup.
85cb4d
+                 * Recheck addr after we got the lock. This may have changed
85cb4d
+                 * while waiting for the lock.
85cb4d
                  */
85cb4d
-                err = apr_sockaddr_info_get(&(worker->cp->addr),
85cb4d
-                                            conn->hostname, APR_UNSPEC,
85cb4d
-                                            conn->port, 0,
85cb4d
-                                            worker->cp->pool);
85cb4d
+                if (!AP_VOLATILIZE_T(apr_sockaddr_t *, worker->cp->addr)) {
85cb4d
+
85cb4d
+                    apr_sockaddr_t *addr;
85cb4d
+
85cb4d
+                    /*
85cb4d
+                     * Worker can have the single constant backend address.
85cb4d
+                     * The single DNS lookup is used once per worker.
85cb4d
+                     * If dynamic change is needed then set the addr to NULL
85cb4d
+                     * inside dynamic config to force the lookup.
85cb4d
+                     */
85cb4d
+                    err = apr_sockaddr_info_get(&addr,
85cb4d
+                                                conn->hostname, APR_UNSPEC,
85cb4d
+                                                conn->port, 0,
85cb4d
+                                                worker->cp->dns_pool);
85cb4d
+                    worker->cp->addr = addr;
85cb4d
+                }
85cb4d
                 conn->addr = worker->cp->addr;
85cb4d
+#if APR_HAS_THREADS
85cb4d
                 if ((uerr = PROXY_THREAD_UNLOCK(worker)) != APR_SUCCESS) {
85cb4d
                     ap_log_rerror(APLOG_MARK, APLOG_ERR, uerr, r, APLOGNO(00946) "unlock");
85cb4d
                 }
85cb4d
+#endif
85cb4d
             }
85cb4d
             else {
85cb4d
                 conn->addr = worker->cp->addr;
85cb4d
@@ -3422,7 +3449,9 @@ PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b, server_rec
85cb4d
             (*runtime)->cp = NULL;
85cb4d
             (*runtime)->balancer = b;
85cb4d
             (*runtime)->s = shm;
85cb4d
+#if APR_HAS_THREADS
85cb4d
             (*runtime)->tmutex = NULL;
85cb4d
+#endif
85cb4d
             rv = ap_proxy_initialize_worker(*runtime, s, conf->pool);
85cb4d
             if (rv != APR_SUCCESS) {
85cb4d
                 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(00966) "Cannot init worker");