From 9366977fe6f6e6c19517d445d529b3d0683c889e Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 16 Sep 2020 15:02:31 -0400 Subject: [PATCH] Copy d_domain before iterating Prevents a bug where the thread can crash due to a change in the d_domain object while running the for loop. By copying and iterating over the copy, this becomes safer. --- node-daemon/pvcnoded/Daemon.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node-daemon/pvcnoded/Daemon.py b/node-daemon/pvcnoded/Daemon.py index a3194e3a..f062fe00 100644 --- a/node-daemon/pvcnoded/Daemon.py +++ b/node-daemon/pvcnoded/Daemon.py @@ -1326,7 +1326,9 @@ def collect_vm_stats(queue): # Toggle state management of dead VMs to restart them if debug: logger.out("Toggle state management of dead VMs to restart them", state='d', prefix='vm-thread') - for domain, instance in this_node.d_domain.items(): + # Make a copy of the d_domain; if not, and it changes in flight, this can fail + fixed_d_domain = this_node.d_domain.copy() + for domain, instance in fixed_d_domain.items(): if domain in this_node.domain_list: # Add the allocated memory to our memalloc value memalloc += instance.getmemory()