summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-06-06 11:03:11 +0000
committerGerrit Code Review <review@openstack.org>2019-06-06 11:03:11 +0000
commit89c4d7ecd0a2a0cd939610d1b35e086b590f13b3 (patch)
tree2df7da4b515ada325a0bb514a22b86650db26dc9
parentec90d53fec72c61a9c41ebf937dfaa9aa768f009 (diff)
parent7b8fd6370c8b04c3836ee4f9d06eaa90c7be5197 (diff)
downloadoslo-messaging-89c4d7ecd0a2a0cd939610d1b35e086b590f13b3.tar.gz
Merge "Fix switch connection destination when a rabbitmq cluster node disappear" into stable/stein
-rw-r--r--oslo_messaging/_drivers/impl_rabbit.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py
index 7bbf8ad..3642be2 100644
--- a/oslo_messaging/_drivers/impl_rabbit.py
+++ b/oslo_messaging/_drivers/impl_rabbit.py
@@ -918,6 +918,14 @@ class Connection(object):
def _heartbeat_thread_job(self):
"""Thread that maintains inactive connections
"""
+ # NOTE(hberaud): Python2 doesn't have ConnectionRefusedError
+ # defined so to switch connections destination on failure
+ # with python2 and python3 we need to wrapp adapt connection refused
+ try:
+ ConnectRefuseError = ConnectionRefusedError
+ except NameError:
+ ConnectRefuseError = socket.error
+
while not self._heartbeat_exit_event.is_set():
with self._connection_lock.for_heartbeat():
@@ -934,7 +942,17 @@ class Connection(object):
self.connection.drain_events(timeout=0.001)
except socket.timeout:
pass
+ # NOTE(hberaud): In a clustered rabbitmq when
+ # a node disappears, we get a ConnectionRefusedError
+ # because the socket get disconnected.
+ # The socket access yields a OSError because the heartbeat
+ # tries to reach an unreachable host (No route to host).
+ # Catch these exceptions to ensure that we call
+ # ensure_connection for switching the
+ # connection destination.
except (socket.timeout,
+ ConnectRefuseError,
+ OSError,
kombu.exceptions.OperationalError) as exc:
LOG.info(_LI("A recoverable connection/channel error "
"occurred, trying to reconnect: %s"), exc)