Merge "Fix switch connection destination when a rabbitmq cluster node disappear"

This commit is contained in:
Zuul 2019-05-20 21:05:57 +00:00 committed by Gerrit Code Review
commit fe0ac3195e

View File

@ -913,6 +913,14 @@ class Connection(object):
def _heartbeat_thread_job(self): def _heartbeat_thread_job(self):
"""Thread that maintains inactive connections """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(): while not self._heartbeat_exit_event.is_set():
with self._connection_lock.for_heartbeat(): with self._connection_lock.for_heartbeat():
@ -929,7 +937,17 @@ class Connection(object):
self.connection.drain_events(timeout=0.001) self.connection.drain_events(timeout=0.001)
except socket.timeout: except socket.timeout:
pass 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, except (socket.timeout,
ConnectRefuseError,
OSError,
kombu.exceptions.OperationalError) as exc: kombu.exceptions.OperationalError) as exc:
LOG.info("A recoverable connection/channel error " LOG.info("A recoverable connection/channel error "
"occurred, trying to reconnect: %s", exc) "occurred, trying to reconnect: %s", exc)