From 5de54b11eeb14d7617d7cf203e2fdb0acffe1dc9 Mon Sep 17 00:00:00 2001 From: Caio Ramos Casimiro Date: Mon, 24 Jun 2024 11:47:56 +0100 Subject: [PATCH] hotfix(metrics) old metrics cleanup `ngx_wa_metrics_init_conf` seems a more appropriate place to set `old_metrics->shm_zone->noreuse` to 1. Then `ngx_wa_metrics_init` only acts according to the then configured values. --- src/common/metrics/ngx_wa_metrics.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/metrics/ngx_wa_metrics.c b/src/common/metrics/ngx_wa_metrics.c index 754e8f470..16d3adc03 100644 --- a/src/common/metrics/ngx_wa_metrics.c +++ b/src/common/metrics/ngx_wa_metrics.c @@ -218,6 +218,8 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf) && (metrics->workers != old_metrics->workers || metrics->config.slab_size != old_metrics->config.slab_size)) { + /* both old and current kv store have to be marked for cleanup */ + old_metrics->shm_zone->noreuse = 1; metrics->shm_zone->noreuse = 1; } @@ -230,7 +232,7 @@ ngx_wa_metrics_init(ngx_wa_metrics_t *metrics, ngx_cycle_t *cycle) { ngx_wasm_shm_kv_t *old_shm_kv; - if (metrics->old_metrics && !metrics->shm_zone->noreuse) { + if (metrics->old_metrics && !metrics->old_metrics->shm_zone->noreuse) { /* reuse old kv store */ metrics->shm->data = metrics->old_metrics->shm->data; return NGX_OK; @@ -240,14 +242,13 @@ ngx_wa_metrics_init(ngx_wa_metrics_t *metrics, ngx_cycle_t *cycle) return NGX_ERROR; } - if (metrics->old_metrics && metrics->shm_zone->noreuse) { - /* mark the old kv store for cleanup during SIGHUP old_cycle free */ - metrics->old_metrics->shm_zone->noreuse = 1; + if (metrics->old_metrics && metrics->old_metrics->shm_zone->noreuse) { + /* relable current kv store as reusable */ metrics->shm_zone->noreuse = 0; - /* realloc old kv store */ old_shm_kv = ngx_wasm_shm_get_kv(metrics->old_metrics->shm); + /* realloc old kv store */ return realloc_metrics(metrics, old_shm_kv->rbtree.root, old_shm_kv->rbtree.sentinel); }