From 8a3b78ca7bb2bb6af1fe25921cfb5f08fe38325c Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 14 Jun 2018 13:17:50 +0200 Subject: [PATCH] Rest api thread can raise an exception during shutdown (#711) catch it and report --- patroni/__init__.py | 5 ++++- tests/test_patroni.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/patroni/__init__.py b/patroni/__init__.py index 40801f65..edf6cf10 100644 --- a/patroni/__init__.py +++ b/patroni/__init__.py @@ -129,7 +129,10 @@ class Patroni(object): signal.signal(signal.SIGTERM, self.sigterm_handler) def shutdown(self): - self.api.shutdown() + try: + self.api.shutdown() + except Exception: + logger.exception('Exception during RestApi.shutdown') self.ha.shutdown() diff --git a/tests/test_patroni.py b/tests/test_patroni.py index d4b46589..d3269798 100644 --- a/tests/test_patroni.py +++ b/tests/test_patroni.py @@ -151,3 +151,7 @@ class TestPatroni(unittest.TestCase): self.assertTrue(self.p.nosync) self.p.tags['nosync'] = None self.assertFalse(self.p.nosync) + + def test_shutdown(self): + self.p.api.shutdown = Mock(side_effect=Exception) + self.p.shutdown()