From 9b8c40a6e105c16f998a4a487f707b200d4f26fa Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Tue, 10 Oct 2023 09:54:24 +0200 Subject: [PATCH] Start thread that will handle SIGCHLD for on_reload callback (#2898) Close #2897 --- patroni/postgresql/callback_executor.py | 4 +++- tests/test_callback_executor.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/patroni/postgresql/callback_executor.py b/patroni/postgresql/callback_executor.py index 3ae073fd..fa645b86 100644 --- a/patroni/postgresql/callback_executor.py +++ b/patroni/postgresql/callback_executor.py @@ -30,7 +30,9 @@ class OnReloadExecutor(CancellableSubprocess): self.cancel(kill=True) self._kill_children() with self._lock: - self._start_process(cmd, close_fds=True) + started = self._start_process(cmd, close_fds=True) + if started and self._process is not None: + Thread(target=self._process.wait).start() class CallbackExecutor(CancellableExecutor, Thread): diff --git a/tests/test_callback_executor.py b/tests/test_callback_executor.py index df2556b9..51c915d9 100644 --- a/tests/test_callback_executor.py +++ b/tests/test_callback_executor.py @@ -35,5 +35,6 @@ class TestCallbackExecutor(unittest.TestCase): ce._invoke_excepthook = Mock() self.assertIsNone(ce.call(callback)) + mock_popen.side_effect = [Mock()] self.assertIsNone(ce.call(['test.sh', 'on_reload', 'replica', 'foo'])) ce.join()