MINOR: proxy: handle shared listener counters preparation from proxy_postcheck()

We used to allocate and prepare listener counters from
check_config_validity() all at once. But it isn't correct, since at that
time listeners's guid are not inserted yet, thus
counters_fe_shared_prepare() cannot work correctly, and so does
shm_stats_file_preload() which is meant to be called even earlier.

Thus in this commit (and to prepare for upcoming shm shared counters
preloading patches), we handle the shared listener counters prep in
proxy_postcheck(), which means that between the allocation and the
prep there is the proper window for listener's guid insertion and shm
counters preloading.

No change of behavior expected when shm shared counters are not
actually used.
This commit is contained in:
Aurelien DARRAGON 2025-08-08 14:56:18 +02:00
parent cdb97cb73e
commit 2cd0afb430
2 changed files with 12 additions and 8 deletions

View File

@ -4279,14 +4279,6 @@ init_proxies_list_stage2:
/* enable separate counters */
if (curproxy->options2 & PR_O2_SOCKSTAT) {
listener->counters = calloc(1, sizeof(*listener->counters));
if (listener->counters) {
if (!counters_fe_shared_prepare(&listener->counters->shared, &listener->guid)) {
ha_free(&listener->counters);
ha_alert("config: %s '%s': out of memory.\n",
proxy_type_str(curproxy), curproxy->id);
}
}
if (!listener->name)
memprintf(&listener->name, "sock-%d", listener->luid);
}

View File

@ -1748,6 +1748,7 @@ struct proxy *alloc_new_proxy(const char *name, unsigned int cap, char **errmsg)
/* post-check for proxies */
static int proxy_postcheck(struct proxy *px)
{
struct listener *listener;
int err_code = ERR_NONE;
/* allocate private memory for shared counters: used as a fallback
@ -1777,6 +1778,17 @@ static int proxy_postcheck(struct proxy *px)
}
list_for_each_entry(listener, &px->conf.listeners, by_fe) {
if (listener->counters) {
if (!counters_fe_shared_prepare(&listener->counters->shared, &listener->guid)) {
ha_free(&listener->counters);
ha_alert("out of memory while setting up shared listener counters for %s %s\n",
proxy_type_str(px), px->id);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
}
}
out:
return err_code;