Skip to content

Commit 9e558c0

Browse files
Fix ConfigManagingActor to handle missing config files gracefully
Eliminate recursive actor crashes when config files are missing. The previous implementation suffered from a critical error pattern: - The `_read_config` method is called at the start of the `_run` method - When no config files existed, an exception would be raised - This exception caused the actor to crash and immediately restart - Restarting triggered the same `_read_config` method - The cycle repeated, creating a persistent crash loop This fix introduces a more robust approach: - Detect missing config files without throwing exceptions - Set up a FileWatcher to monitor for future config file creation - call `_read_config` method as soon as any config file is crated. Signed-off-by: Elzbieta Kotulska <[email protected]>
1 parent f71322e commit 9e558c0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/frequenz/sdk/config/_config_managing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(
107107
self._force_polling: bool = force_polling
108108
self._polling_interval: timedelta = polling_interval
109109

110-
def _read_config(self) -> abc.Mapping[str, Any]:
110+
def _read_config(self) -> abc.Mapping[str, Any] | None:
111111
"""Read the contents of the configuration file.
112112
113113
Returns:
@@ -138,14 +138,18 @@ def _read_config(self) -> abc.Mapping[str, Any]:
138138
error_count += 1
139139

140140
if error_count == len(self._config_paths):
141-
raise ValueError(f"{self}: Can't read any of the config files")
141+
_logger.error(
142+
"%s: Can't read any of the config files, ignoring config update.", self
143+
)
144+
return None
142145

143146
return config
144147

145148
async def send_config(self) -> None:
146149
"""Send the configuration to the output sender."""
147150
config = self._read_config()
148-
await self._output.send(config)
151+
if config is not None:
152+
await self._output.send(config)
149153

150154
async def _run(self) -> None:
151155
"""Monitor for and send configuration file updates.

0 commit comments

Comments
 (0)