From bbb9ab163b4d0a9cb556e741215ad082762e8dbf Mon Sep 17 00:00:00 2001 From: Daniel Bengtsson Date: Mon, 31 Mar 2025 11:25:59 +0200 Subject: [PATCH] Fix concurrent access crash in _all_opt_infos() This patch avoids the following error raised when configuration options are modified (e.g. by registering or unregistering an opt) during iteration in mutate_config_files() or related methods: RuntimeError: dictionary changed size during iteration The error was observed in Neutron after oslo.service was refactored to use dynamic backends, slightly changing signal handling and restart timing. We fix this by copying the values of the affected dicts before iterating, ensuring the iteration is stable and thread-safe. Closes-Bug: #2100001 Change-Id: Ic576f7031e07f5615cd1fbc157ddfbb89b61a130 --- oslo_config/cfg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py index 58982616..e73d89d9 100644 --- a/oslo_config/cfg.py +++ b/oslo_config/cfg.py @@ -2736,10 +2736,10 @@ class ConfigOpts(abc.Mapping): def _all_opt_infos(self): """A generator function for iteration opt infos.""" - for info in self._opts.values(): + for info in list(self._opts.values()): yield info, None - for group in self._groups.values(): - for info in group._opts.values(): + for group in list(self._groups.values()): + for info in list(group._opts.values()): yield info, group def _all_cli_opts(self):