From 1c4d395d5a0445a60d3821179862636e4dc4509e Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 16 Jan 2020 14:34:58 +0100 Subject: [PATCH] Handle exception from Ha.shutdown (#1351) During the shutdown Patroni is trying to update its status in the DCS. If the DCS is inaccessible an exception might be raised. Lack of exception handling prevents logger thread from stopping. Fixes https://github.com/zalando/patroni/issues/1344 --- patroni/__init__.py | 5 ++++- tests/test_patroni.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/patroni/__init__.py b/patroni/__init__.py index d5fd9464..2d0bc01c 100644 --- a/patroni/__init__.py +++ b/patroni/__init__.py @@ -159,7 +159,10 @@ class Patroni(object): self.api.shutdown() except Exception: logger.exception('Exception during RestApi.shutdown') - self.ha.shutdown() + try: + self.ha.shutdown() + except Exception: + logger.exception('Exception during Ha.shutdown') self.logger.shutdown() diff --git a/tests/test_patroni.py b/tests/test_patroni.py index 1611d970..0b395d59 100644 --- a/tests/test_patroni.py +++ b/tests/test_patroni.py @@ -174,6 +174,7 @@ class TestPatroni(unittest.TestCase): @patch.object(Thread, 'join', Mock()) def test_shutdown(self): self.p.api.shutdown = Mock(side_effect=Exception) + self.p.ha.shutdown = Mock(side_effect=Exception) self.p.shutdown() def test_check_psycopg2(self):