Skip to content

Commit 2cd0afb

Browse files
committed
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.
1 parent cdb97cb commit 2cd0afb

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/cfgparse.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,14 +4279,6 @@ int check_config_validity()
42794279
/* enable separate counters */
42804280
if (curproxy->options2 & PR_O2_SOCKSTAT) {
42814281
listener->counters = calloc(1, sizeof(*listener->counters));
4282-
if (listener->counters) {
4283-
if (!counters_fe_shared_prepare(&listener->counters->shared, &listener->guid)) {
4284-
ha_free(&listener->counters);
4285-
ha_alert("config: %s '%s': out of memory.\n",
4286-
proxy_type_str(curproxy), curproxy->id);
4287-
}
4288-
4289-
}
42904282
if (!listener->name)
42914283
memprintf(&listener->name, "sock-%d", listener->luid);
42924284
}

src/proxy.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,7 @@ struct proxy *alloc_new_proxy(const char *name, unsigned int cap, char **errmsg)
17481748
/* post-check for proxies */
17491749
static int proxy_postcheck(struct proxy *px)
17501750
{
1751+
struct listener *listener;
17511752
int err_code = ERR_NONE;
17521753

17531754
/* allocate private memory for shared counters: used as a fallback
@@ -1777,6 +1778,17 @@ static int proxy_postcheck(struct proxy *px)
17771778

17781779
}
17791780

1781+
list_for_each_entry(listener, &px->conf.listeners, by_fe) {
1782+
if (listener->counters) {
1783+
if (!counters_fe_shared_prepare(&listener->counters->shared, &listener->guid)) {
1784+
ha_free(&listener->counters);
1785+
ha_alert("out of memory while setting up shared listener counters for %s %s\n",
1786+
proxy_type_str(px), px->id);
1787+
err_code |= ERR_ALERT | ERR_FATAL;
1788+
goto out;
1789+
}
1790+
}
1791+
}
17801792

17811793
out:
17821794
return err_code;

0 commit comments

Comments
 (0)