On Tue, Feb 6, 2018 at 6:17 PM, Stefan Eissing <stefan.eiss...@greenbytes.de> wrote: > > >> Am 06.02.2018 um 16:14 schrieb Jim Jagielski <j...@jagunet.com>: >> >> I don't think it does. > > I do not understand. I feel that I am missing something here. > > You're saying that the scenario does not exist or that it does not trigger > the described effect?
FWIW, patch and logs attached, for a test with and without the changes proposed for the ID. With the patch SHMs are reused when a blank line is added before the vhost, without they are not... This is trunk, after r1822509, while before this commit (i.e. mod_slotmem_shm of 2.4.x) SHMs are not reused even with no configuration change (tested too, no logs attached here).
Index: modules/proxy/mod_proxy_balancer.c =================================================================== --- modules/proxy/mod_proxy_balancer.c (revision 1823257) +++ modules/proxy/mod_proxy_balancer.c (working copy) @@ -22,6 +22,7 @@ #include "apr_version.h" #include "ap_hooks.h" #include "apr_date.h" +#include "apr_escape.h" #include "mod_watchdog.h" static const char *balancer_mutex_type = "proxy-balancer-shm"; @@ -730,6 +731,101 @@ static apr_status_t lock_remove(void *data) return(0); } +#define USE_PATCH 1 +#if USE_PATCH +static const char *get_server_id(server_rec *s, apr_pool_t *p, int aliases) +{ + apr_md5_ctx_t md5_ctx; + unsigned char md5[APR_MD5_DIGESTSIZE]; + server_addr_rec *addr; + const char **names; + int i; + + /* Assumes the unique ID of a vhost are its IP(s):port(s), its ServerName, + * and its ServerAlias(es). Should two or more vhosts have this same + * combination, the first one would always be selected to handle the + * requests, so this shouldn't be an issue... + */ + apr_md5_init(&md5_ctx); + for (addr = s->addrs; addr; addr = addr->next) { + char host_ip[64]; /* for any IPv[46] string */ + apr_sockaddr_ip_getbuf(host_ip, sizeof host_ip, + addr->host_addr); + + apr_md5_update(&md5_ctx, (unsigned char *)host_ip, + strlen(host_ip)); + apr_md5_update(&md5_ctx, (unsigned char *)&addr->host_port, + sizeof(addr->host_port)); + if (aliases) { + if (s->names) { + names = (const char **)s->names->elts; + for (i = 0; i < s->names->nelts; ++i) { + apr_md5_update(&md5_ctx, (unsigned char *)names[i], + sizeof(names[i])); + } + } + if (s->wild_names) { + names = (const char **)s->wild_names->elts; + for (i = 0; i < s->wild_names->nelts; ++i) { + apr_md5_update(&md5_ctx, (unsigned char *)names[i], + sizeof(names[i])); + } + } + } + } + if (s->server_hostname) { + apr_md5_update(&md5_ctx, (unsigned char *)s->server_hostname, + strlen(s->server_hostname)); + } + apr_md5_update(&md5_ctx, (unsigned char *)&s->port, + sizeof(s->port)); + apr_md5_final(md5, &md5_ctx); + + return apr_pescape_hex(p, md5, sizeof md5, 0); +} + +static apr_array_header_t *make_servers_ids(server_rec *main_s, apr_pool_t *p, + apr_array_header_t *rec) +{ + server_rec *s = main_s; + apr_array_header_t *ids = rec; + apr_hash_t *dups = apr_hash_make(p); + int *dup; + + if (ids) { + apr_array_clear(ids); + } + else { + ids = apr_array_make(p, 10, sizeof(const char *)); + } + + for (s = main_s; s; s = s->next) { + const char *id = get_server_id(s, p, !!rec); + + /* Handle collisions, that's unique ID! */ + dup = apr_hash_get(dups, id, APR_HASH_KEY_STRING); + if (dup) { + if (!rec) { + /* retry with aliases */ + apr_hash_clear(dups); + make_servers_ids(main_s, p, ids); + break; + } + ++*dup; + id = apr_psprintf(p, "%s.%x", id, *dup); + } + else { + dup = apr_pcalloc(p, sizeof *dup); + apr_hash_set(dups, id, APR_HASH_KEY_STRING, dup); + } + + APR_ARRAY_PUSH(ids, const char*) = id; + } + + return ids; +} +#endif + /* post_config hook: */ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) @@ -738,6 +834,10 @@ static int balancer_post_config(apr_pool_t *pconf, proxy_server_conf *conf; ap_slotmem_instance_t *new = NULL; apr_time_t tstamp; +#if USE_PATCH + apr_array_header_t *server_ids; + int server_idx = 0; +#endif /* balancer_post_config() will be called twice during startup. So, don't * set up the static data the 1st time through. */ @@ -768,6 +868,10 @@ static int balancer_post_config(apr_pool_t *pconf, return !OK; } +#if USE_PATCH + server_ids = make_servers_ids(s, ptemp, NULL); +#endif + tstamp = apr_time_now(); /* * Go thru each Vhost and create the shared mem slotmem for @@ -775,16 +879,21 @@ static int balancer_post_config(apr_pool_t *pconf, */ while (s) { int i,j; - char *id; + const char *server_id; proxy_balancer *balancer; ap_slotmem_type_t type; void *sconf = s->module_config; conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module); + /* * During create_proxy_config() we created a dummy id. Now that * we have identifying info, we can create the real id */ - id = apr_psprintf(pconf, "%s.%s.%d.%s.%s.%u.%s", +#if USE_PATCH + server_id = APR_ARRAY_IDX(server_ids, server_idx++, const char*); + conf->id = apr_pstrcat(pconf, "ap_lb.", server_id, NULL); +#else + server_id = apr_psprintf(pconf, "%s.%s.%d.%s.%s.%u.%s", (s->server_scheme ? s->server_scheme : "????"), (s->server_hostname ? s->server_hostname : "???"), (int)s->port, @@ -793,7 +902,8 @@ static int balancer_post_config(apr_pool_t *pconf, s->defn_line_number, (s->error_fname ? s->error_fname : DEFAULT_ERRORLOG)); conf->id = apr_psprintf(pconf, "p%x", - ap_proxy_hashfunc(id, PROXY_HASHFUNC_DEFAULT)); + ap_proxy_hashfunc(server_id, PROXY_HASHFUNC_DEFAULT)); +#endif if (conf->bslot) { /* Shared memory already created for this proxy_server_conf. */
<start> [Tue Feb 06 17:26:57.096020 2018] [proxy_balancer:debug] [pid 9079:tid 140016323500288] mod_proxy_balancer.c(922): AH01178: Doing balancers create: 480, 1 (6) [Tue Feb 06 17:26:57.096026 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(409): AH02602: create didn't find /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b.shm in global list [Tue Feb 06 17:26:57.096027 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(419): AH02300: create /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b.shm: 480/6 [Tue Feb 06 17:26:57.096058 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(434): AH02611: create: apr_shm_create(/home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b.shm) succeeded [Tue Feb 06 17:26:57.096069 2018] [proxy:debug] [pid 9079:tid 140016323500288] proxy_util.c(1220): AH02337: copying shm[0] (0x7f5817455020) for balancer://mycluster [Tue Feb 06 17:26:57.096094 2018] [proxy_balancer:debug] [pid 9079:tid 140016323500288] mod_proxy_balancer.c(992): AH01184: Doing workers create: balancer://mycluster (pc497843b_mycluster), 1240, 2 [0] [Tue Feb 06 17:26:57.096097 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(409): AH02602: create didn't find /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b_mycluster.shm in global list [Tue Feb 06 17:26:57.096099 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(419): AH02300: create /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b_mycluster.shm: 1240/2 [Tue Feb 06 17:26:57.096113 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(434): AH02611: create: apr_shm_create(/home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b_mycluster.shm) succeeded [Tue Feb 06 17:26:57.096117 2018] [proxy:debug] [pid 9079:tid 140016323500288] proxy_util.c(1809): AH02338: copying shm[0] (0x7f5817453020) for worker: http://127.0.0.1/ [Tue Feb 06 17:26:57.096119 2018] [proxy:debug] [pid 9079:tid 140016323500288] proxy_util.c(1809): AH02338: copying shm[1] (0x7f58174534f8) for worker: http://127.0.0.2/ [Tue Feb 06 17:26:57.096638 2018] [mpm_event:notice] [pid 9079:tid 140016323500288] AH00489: Apache/2.5.1-dev (Unix) OpenSSL/1.1.0f configured -- resuming normal operations [] [Tue Feb 06 17:26:57.096803 2018] [slotmem_shm:debug] [pid 9080:tid 140016323500288] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b.shm [Tue Feb 06 17:26:57.096824 2018] [slotmem_shm:debug] [pid 9080:tid 140016323500288] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b.shm: 480/6 [Tue Feb 06 17:26:57.096833 2018] [slotmem_shm:debug] [pid 9080:tid 140016323500288] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b_mycluster.shm [Tue Feb 06 17:26:57.096836 2018] [slotmem_shm:debug] [pid 9080:tid 140016323500288] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-pc497843b_mycluster.shm: 1240/2 <graceful restart> [Tue Feb 06 17:29:11.269896 2018] [mpm_event:notice] [pid 9079:tid 140016323500288] AH00493: SIGUSR1 received. Doing graceful restart [] [Tue Feb 06 17:29:11.275688 2018] [proxy_balancer:debug] [pid 9079:tid 140016323500288] mod_proxy_balancer.c(922): AH01178: Doing balancers create: 480, 1 (6) [Tue Feb 06 17:29:11.275694 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(409): AH02602: create didn't find /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa.shm in global list [Tue Feb 06 17:29:11.275697 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(419): AH02300: create /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa.shm: 480/6 [Tue Feb 06 17:29:11.275741 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(434): AH02611: create: apr_shm_create(/home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa.shm) succeeded [Tue Feb 06 17:29:11.275755 2018] [proxy:debug] [pid 9079:tid 140016323500288] proxy_util.c(1220): AH02337: copying shm[0] (0x7f5817454020) for balancer://mycluster [Tue Feb 06 17:29:11.275784 2018] [proxy_balancer:debug] [pid 9079:tid 140016323500288] mod_proxy_balancer.c(992): AH01184: Doing workers create: balancer://mycluster (p523bf7fa_mycluster), 1240, 2 [0] [Tue Feb 06 17:29:11.275790 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(409): AH02602: create didn't find /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa_mycluster.shm in global list [Tue Feb 06 17:29:11.275792 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(419): AH02300: create /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa_mycluster.shm: 1240/2 [Tue Feb 06 17:29:11.275807 2018] [slotmem_shm:debug] [pid 9079:tid 140016323500288] mod_slotmem_shm.c(434): AH02611: create: apr_shm_create(/home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa_mycluster.shm) succeeded [Tue Feb 06 17:29:11.275813 2018] [proxy:debug] [pid 9079:tid 140016323500288] proxy_util.c(1809): AH02338: copying shm[0] (0x7f5817451020) for worker: http://127.0.0.1/ [Tue Feb 06 17:29:11.275816 2018] [proxy:debug] [pid 9079:tid 140016323500288] proxy_util.c(1809): AH02338: copying shm[1] (0x7f58174514f8) for worker: http://127.0.0.2/ [Tue Feb 06 17:29:11.275997 2018] [mpm_event:notice] [pid 9079:tid 140016323500288] AH00489: Apache/2.5.1-dev (Unix) OpenSSL/1.1.0f configured -- resuming normal operations [] [Tue Feb 06 17:29:11.276836 2018] [slotmem_shm:debug] [pid 9135:tid 140016323500288] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa.shm [Tue Feb 06 17:29:11.276867 2018] [slotmem_shm:debug] [pid 9135:tid 140016323500288] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa.shm: 480/6 [Tue Feb 06 17:29:11.276882 2018] [slotmem_shm:debug] [pid 9135:tid 140016323500288] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa_mycluster.shm [Tue Feb 06 17:29:11.276886 2018] [slotmem_shm:debug] [pid 9135:tid 140016323500288] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-p523bf7fa_mycluster.shm: 1240/2
<start> [Tue Feb 06 17:37:36.051861 2018] [proxy_balancer:debug] [pid 24070:tid 140245604485376] mod_proxy_balancer.c(922): AH01178: Doing balancers create: 480, 1 (6) [Tue Feb 06 17:37:36.051867 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(409): AH02602: create didn't find /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm in global list [Tue Feb 06 17:37:36.051869 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(419): AH02300: create /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm: 480/6 [Tue Feb 06 17:37:36.051910 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(434): AH02611: create: apr_shm_create(/home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm) succeeded [Tue Feb 06 17:37:36.051923 2018] [proxy:debug] [pid 24070:tid 140245604485376] proxy_util.c(1220): AH02337: copying shm[0] (0x7f8d797b8020) for balancer://mycluster [Tue Feb 06 17:37:36.051962 2018] [proxy_balancer:debug] [pid 24070:tid 140245604485376] mod_proxy_balancer.c(992): AH01184: Doing workers create: balancer://mycluster (ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster), 1240, 2 [0] [Tue Feb 06 17:37:36.051967 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(409): AH02602: create didn't find /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm in global list [Tue Feb 06 17:37:36.051969 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(419): AH02300: create /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm: 1240/2 [Tue Feb 06 17:37:36.051986 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(434): AH02611: create: apr_shm_create(/home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm) succeeded [Tue Feb 06 17:37:36.051991 2018] [proxy:debug] [pid 24070:tid 140245604485376] proxy_util.c(1809): AH02338: copying shm[0] (0x7f8d797b6020) for worker: http://127.0.0.1/ [Tue Feb 06 17:37:36.051994 2018] [proxy:debug] [pid 24070:tid 140245604485376] proxy_util.c(1809): AH02338: copying shm[1] (0x7f8d797b64f8) for worker: http://127.0.0.2/ [Tue Feb 06 17:37:36.052680 2018] [mpm_event:notice] [pid 24070:tid 140245604485376] AH00489: Apache/2.5.1-dev (Unix) OpenSSL/1.1.0f configured -- resuming normal operations [] [Tue Feb 06 17:37:36.052879 2018] [slotmem_shm:debug] [pid 24071:tid 140245604485376] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm [Tue Feb 06 17:37:36.052907 2018] [slotmem_shm:debug] [pid 24071:tid 140245604485376] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm: 480/6 [Tue Feb 06 17:37:36.052917 2018] [slotmem_shm:debug] [pid 24071:tid 140245604485376] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm [Tue Feb 06 17:37:36.052922 2018] [slotmem_shm:debug] [pid 24071:tid 140245604485376] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm: 1240/2 <graceful restart> [Tue Feb 06 17:37:54.238104 2018] [mpm_event:notice] [pid 24070:tid 140245604485376] AH00493: SIGUSR1 received. Doing graceful restart [] [Tue Feb 06 17:37:54.243590 2018] [proxy_balancer:debug] [pid 24070:tid 140245604485376] mod_proxy_balancer.c(922): AH01178: Doing balancers create: 480, 1 (6) [Tue Feb 06 17:37:54.243595 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(399): AH02603: create found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm in global list [Tue Feb 06 17:37:54.243608 2018] [proxy:debug] [pid 24070:tid 140245604485376] proxy_util.c(1220): AH02337: re-using shm[0] (0x7f8d797b8020) for balancer://mycluster [Tue Feb 06 17:37:54.243612 2018] [proxy_balancer:debug] [pid 24070:tid 140245604485376] mod_proxy_balancer.c(992): AH01184: Doing workers create: balancer://mycluster (ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster), 1240, 2 [0] [Tue Feb 06 17:37:54.243616 2018] [slotmem_shm:debug] [pid 24070:tid 140245604485376] mod_slotmem_shm.c(399): AH02603: create found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm in global list [Tue Feb 06 17:37:54.243619 2018] [proxy:debug] [pid 24070:tid 140245604485376] proxy_util.c(1809): AH02338: re-using shm[0] (0x7f8d797b6020) for worker: http://127.0.0.1/ [Tue Feb 06 17:37:54.243622 2018] [proxy:debug] [pid 24070:tid 140245604485376] proxy_util.c(1809): AH02338: re-using shm[1] (0x7f8d797b64f8) for worker: http://127.0.0.2/ [Tue Feb 06 17:37:54.243765 2018] [mpm_event:notice] [pid 24070:tid 140245604485376] AH00489: Apache/2.5.1-dev (Unix) OpenSSL/1.1.0f configured -- resuming normal operations [] [Tue Feb 06 17:37:54.244461 2018] [slotmem_shm:debug] [pid 24126:tid 140245604485376] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm [Tue Feb 06 17:37:54.244496 2018] [slotmem_shm:debug] [pid 24126:tid 140245604485376] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937.shm: 480/6 [Tue Feb 06 17:37:54.244505 2018] [slotmem_shm:debug] [pid 24126:tid 140245604485376] mod_slotmem_shm.c(517): AH02301: attach looking for /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm [Tue Feb 06 17:37:54.244509 2018] [slotmem_shm:debug] [pid 24126:tid 140245604485376] mod_slotmem_shm.c(530): AH02302: attach found /home/yle/src/apache/install/httpd/trunk/logs/slotmem-shm-ap_lb.7193ccfd9184657ce8607ee0e83a3937_mycluster.shm: 1240/2