From 5a7066e4201b13a197364ee6d76bc4a6d3e2c565 Mon Sep 17 00:00:00 2001 From: Alexander Olekhnovich Date: Wed, 10 Apr 2024 14:07:36 +0200 Subject: [PATCH] Fix a potential issue with race condition when reloading a config When SIGHUP is sent during load_config it's possible that `config_reload_pending` will be set to `False` and new reload won't happen. --- pglookout/pglookout.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pglookout/pglookout.py b/pglookout/pglookout.py index 5e92e80..f656773 100755 --- a/pglookout/pglookout.py +++ b/pglookout/pglookout.py @@ -69,7 +69,7 @@ def __init__(self, config_path): self._config_version_applied = 0 self._failover_on_disconnect = True self.load_config() - self.config_reload_pending = False + self.config_reload_pending = Queue() signal.signal(signal.SIGHUP, self.sighup) signal.signal(signal.SIGINT, self.quit) @@ -113,7 +113,7 @@ def sighup(self, _signal=None, _frame=None): _signal, _frame, ) - self.config_reload_pending = True + self.config_reload_pending.put(True) def load_config(self): self.log.debug("Loading JSON config from: %r", self.config_path) @@ -858,9 +858,9 @@ def _get_check_interval(self) -> float: def main_loop(self): while self.running: - if self.config_reload_pending: + while not self.config_reload_pending.empty(): self.load_config() - self.config_reload_pending = False + self.config_reload_pending.get() try: self._apply_latest_config_version() except Exception as ex: # pylint: disable=broad-except