From 6a6f7a0a5568b1f2a84aeb36041bce83b810c21b Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 20 Jun 2024 19:53:05 -0700 Subject: [PATCH] hotfix(metrics) cleanup old metrics shm during SIGHUP reallocation In `ngx_init_cycle`, this section does a cleanup of `old_cycle` shms: /* close and delete stuff that lefts from an old cycle */ /* free the unnecessary shared memory */ ... Prior to this change, old metrics shms would be marked for reuse (i.e. `noreuse == 0`) and thus not freed. The change makes it so we hit the `ngx_init_cycle` line below: ngx_shm_free(&oshm_zone[i].shm); --- src/common/metrics/ngx_wa_metrics.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/metrics/ngx_wa_metrics.c b/src/common/metrics/ngx_wa_metrics.c index 4187a136d..754e8f470 100644 --- a/src/common/metrics/ngx_wa_metrics.c +++ b/src/common/metrics/ngx_wa_metrics.c @@ -241,6 +241,11 @@ ngx_wa_metrics_init(ngx_wa_metrics_t *metrics, ngx_cycle_t *cycle) } 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; + metrics->shm_zone->noreuse = 0; + + /* realloc old kv store */ old_shm_kv = ngx_wasm_shm_get_kv(metrics->old_metrics->shm); return realloc_metrics(metrics, old_shm_kv->rbtree.root,