Skip to content

Commit

Permalink
Fix a potential issue with race condition when reloading a config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexole committed Apr 10, 2024
1 parent 7c5e53c commit 5a7066e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pglookout/pglookout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a7066e

Please sign in to comment.