From 3c4e359c01e9f694abf74f8fd69826c5d133f6b8 Mon Sep 17 00:00:00 2001 From: Benjamin Tovar Date: Tue, 27 Oct 2026 09:33:07 -0400 Subject: [PATCH] rmonitor: delay inserting processes found by polling. Before we would try to find children of processes while iterating the processes table. If children were found before they were discovered by a fork message, we would modify the processes table, which is not allowed anymore. --- resource_monitor/src/resource_monitor.c | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/resource_monitor/src/resource_monitor.c b/resource_monitor/src/resource_monitor.c index 8f8a042be7..574016d3f8 100644 --- a/resource_monitor/src/resource_monitor.c +++ b/resource_monitor/src/resource_monitor.c @@ -1367,7 +1367,11 @@ void rmonitor_add_children_by_polling() uint64_t pid; struct rmonitor_process_info *p; - uint64_t *children = NULL; + + /* rmonitor_track_process inserts into processes, which cannot be done + * while iterating over processes. Collect the children first. */ + uint64_t *found = NULL; + int found_count = 0; ITABLE_ITERATE(processes, iteration, pid, p) { @@ -1375,21 +1379,26 @@ void rmonitor_add_children_by_polling() continue; } + uint64_t *children = NULL; int n = rmonitor_get_children(pid, &children); - if (n < 1) { - continue; - } - - int i; - for (i = 0; i < n; i++) { - if (rmonitor_track_process(children[i])) { - debug(D_RMON, "added by polling pid %" PRIu64, children[i]); - } + if (n > 0) { + found = xxrealloc(found, (found_count + n) * sizeof(*found)); + memcpy(found + found_count, children, n * sizeof(*found)); + found_count += n; } free(children); } + + int i; + for (i = 0; i < found_count; i++) { + if (rmonitor_track_process(found[i])) { + debug(D_RMON, "added by polling pid %" PRIu64, found[i]); + } + } + + free(found); } void cleanup_zombie(struct rmonitor_process_info *p)