Handle unexpected exceptions in etcd.

Previously, patroni would die after receiving an exception
other than RetryFailedError, etcd.EtcdException from etcd.
We have observed an AttributeError raised by etcd on some
occasions. With this change, we demote ourselves, but not
terminate on such exceptions.
This commit is contained in:
Oleksii Kliukin
2015-11-17 16:08:58 +01:00
parent 57f19fb149
commit fef7d45208
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -143,6 +143,10 @@ def catch_etcd_errors(func):
return not func(*args, **kwargs) is None
except (RetryFailedError, etcd.EtcdException):
return False
except:
logger.exception("")
raise EtcdError("unexpected error")
return wrapper
+5 -1
View File
@@ -8,7 +8,7 @@ import unittest
from dns.exception import DNSException
from mock import Mock, patch
from patroni.dcs import Cluster, DCSError, Leader
from patroni.etcd import Client, Etcd
from patroni.etcd import Client, Etcd, EtcdError
class MockResponse:
@@ -266,3 +266,7 @@ class TestEtcd(unittest.TestCase):
self.etcd.watch(4.5)
self.etcd.watch(9.5)
self.etcd.watch(100)
@patch('patroni.etcd.Etcd.retry', Mock(side_effect=AttributeError("foo")))
def test_other_exceptions(self):
self.assertRaises(EtcdError, self.etcd.cancel_initialization)