Skip to content

Commit

Permalink
prometheus: unlock stats mods on error
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Nov 24, 2021
1 parent 7fb5ddf commit 85e0e53
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/prometheus/prometheus.c
Expand Up @@ -585,9 +585,11 @@ static inline int prom_push_stat(stat_var *stat, str *page, int max_len,
}
}

#define PROM_PUSH_STAT(_s) \
#define PROM_PUSH_STAT(_s, _m) \
do { \
if (prom_push_stat(_s, page, buffer->len, &groups, &label_groups) < 0) { \
if (_m) \
stats_mod_unlock(_m); \
LM_ERR("out of memory for stats\n"); \
prom_groups_free(&groups, &label_groups); \
return MI_HTTP_INTERNAL_ERR_CODE; \
Expand Down Expand Up @@ -634,7 +636,7 @@ int prom_answer_to_connection (void *cls, void *connection,
while ((mod = module_stats_iterate(mod)) != NULL) {
stats_mod_lock(mod);
for (stat = mod->head; stat; stat = stat->lnext)
PROM_PUSH_STAT(stat);
PROM_PUSH_STAT(stat, mod);
stats_mod_unlock(mod);
}
goto end;
Expand All @@ -651,7 +653,7 @@ int prom_answer_to_connection (void *cls, void *connection,
}
stats_mod_lock(s->mod);
for (stat = s->mod->head; stat; stat = stat->lnext)
PROM_PUSH_STAT(stat);
PROM_PUSH_STAT(stat, s->mod);
stats_mod_unlock(s->mod);
}

Expand All @@ -664,7 +666,7 @@ int prom_answer_to_connection (void *cls, void *connection,
continue;
*s->stat = stat;
}
PROM_PUSH_STAT(*s->stat);
PROM_PUSH_STAT(*s->stat, NULL);
}
end:
list_for_each(grp, &label_groups) {
Expand Down

0 comments on commit 85e0e53

Please sign in to comment.