diff options
author | Mehdi Abaakouk <sileht@redhat.com> | 2015-12-04 14:57:03 +0100 |
---|---|---|
committer | Mehdi Abaakouk <sileht@redhat.com> | 2015-12-09 09:07:59 +0100 |
commit | 47c6c8ebbf92c8794ebbeaca76e3728e4a748f69 (patch) | |
tree | fca0483ee1834323742e110f0e0ddbdc7d734099 | |
parent | b4ec4c4e86cdf18fbc47c154cabfb1cc86c4dc96 (diff) | |
download | oslo-messaging-47c6c8ebbf92c8794ebbeaca76e3728e4a748f69.tar.gz |
Fix reconnection when heartbeat is missed
When a heartbeat is missing we call ensure_connection()
that runs a dummy method to trigger the reconnection
code in kombu. But also the code is triggered only if the
channel is None.
In case of the heartbeat threads we didn't reset the channel
before reconnecting, so the dummy method doesn't do anything.
This change sets the channel to None to ensure the connection
is reestablished before the dummy method is run.
Also it replaces the dummy method by checking the kombu connection
object. So we are sure the connection is reestablished.
Closes-bug: #1493890
(cherry picked from commit I39f8cd23c5a5498e6f4c1aa3236ed27f3b5d7c9a)
Change-Id: Id98d4054ecbc787e0d44884a9e4c48e3fae803b2
-rw-r--r-- | oslo_messaging/_drivers/impl_rabbit.py | 6 | ||||
-rw-r--r-- | oslo_messaging/tests/drivers/test_impl_rabbit.py | 2 | ||||
-rw-r--r-- | tests/drivers/test_impl_rabbit.py | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py index 9716b9c..f6e0f72 100644 --- a/oslo_messaging/_drivers/impl_rabbit.py +++ b/oslo_messaging/_drivers/impl_rabbit.py @@ -778,7 +778,10 @@ class Connection(object): return False def ensure_connection(self): - self.ensure(method=lambda: True) + # NOTE(sileht): we reset the channel and ensure + # the kombu underlying connection works + self._set_current_channel(None) + self.ensure(method=lambda: self.connection.connection) def ensure(self, method, retry=None, recoverable_error_callback=None, error_callback=None, @@ -919,7 +922,6 @@ class Connection(object): try: self._set_current_channel(self.connection.channel()) except recoverable_errors: - self._set_current_channel(None) self.ensure_connection() self.consumers = [] self.consumer_num = itertools.count(1) diff --git a/oslo_messaging/tests/drivers/test_impl_rabbit.py b/oslo_messaging/tests/drivers/test_impl_rabbit.py index 011224b..e4cc1b4 100644 --- a/oslo_messaging/tests/drivers/test_impl_rabbit.py +++ b/oslo_messaging/tests/drivers/test_impl_rabbit.py @@ -821,6 +821,8 @@ class RpcKombuHATestCase(test_utils.BaseTestCase): 'kombu.connection.Connection.connect', side_effect=self.kombu_connect)) self.useFixture(mockpatch.Patch( + 'kombu.connection.Connection.connection')) + self.useFixture(mockpatch.Patch( 'kombu.connection.Connection.channel')) # starting from the first broker in the list diff --git a/tests/drivers/test_impl_rabbit.py b/tests/drivers/test_impl_rabbit.py index 7b58212..f3c2e56 100644 --- a/tests/drivers/test_impl_rabbit.py +++ b/tests/drivers/test_impl_rabbit.py @@ -725,6 +725,8 @@ class RpcKombuHATestCase(test_utils.BaseTestCase): 'kombu.connection.Connection.connect', side_effect=self.kombu_connect)) self.useFixture(mockpatch.Patch( + 'kombu.connection.Connection.connection')) + self.useFixture(mockpatch.Patch( 'kombu.connection.Connection.channel')) # starting from the first broker in the list |