Skip to content

Commit

Permalink
hotfix(metrics) cleanup old metrics shm during SIGHUP reallocation
Browse files Browse the repository at this point in the history
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);

The `metrics->shm_zone->noreuse` flag is still set on the new shm after
a SIGHUP/realloc, but at this point it has no effect on the new shm.
  • Loading branch information
thibaultcha committed Jun 21, 2024
1 parent 7dcd7a3 commit f9b61c5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/common/metrics/ngx_wa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ 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;

/* 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,
Expand Down

0 comments on commit f9b61c5

Please sign in to comment.