From 0fb20d8d49f21bee455420ec5870145722c0e9db Mon Sep 17 00:00:00 2001 From: Dmitry Mescheryakov Date: Tue, 2 Feb 2016 00:26:32 +0300 Subject: [PATCH] Correctly set socket timeout for publishing Previously a wrong attribute was taken which does not work with current versions of kombu and amqp we have in gate. Change-Id: I9dc2453be3047f993930c2b5c1e74720c8c3b26c --- oslo_messaging/_drivers/impl_rabbit.py | 12 +++++++++++- oslo_messaging/tests/drivers/test_impl_rabbit.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py index 34a25402c..f8729d32a 100644 --- a/oslo_messaging/_drivers/impl_rabbit.py +++ b/oslo_messaging/_drivers/impl_rabbit.py @@ -806,7 +806,17 @@ class Connection(object): # or the producer.send return only when the system socket # timeout if reach. kombu doesn't allow use to customise this # timeout so for py-amqp we tweak ourself - sock = getattr(self.connection.transport, 'sock', None) + # NOTE(dmitryme): Current approach works with amqp==1.4.9 and + # kombu==3.0.33. Once the commit below is released, we should + # try to set the socket timeout in the constructor: + # https://github.com/celery/py-amqp/pull/64 + try: + sock = self.channel.connection.sock + except AttributeError as e: + # Level is set to debug because otherwise we would spam the logs + LOG.debug('Failed to get socket attribute: %s' % str(e)) + sock = None + if sock: orig_timeout = sock.gettimeout() sock.settimeout(timeout) diff --git a/oslo_messaging/tests/drivers/test_impl_rabbit.py b/oslo_messaging/tests/drivers/test_impl_rabbit.py index 676c81f41..dc136873e 100644 --- a/oslo_messaging/tests/drivers/test_impl_rabbit.py +++ b/oslo_messaging/tests/drivers/test_impl_rabbit.py @@ -90,11 +90,11 @@ class TestHeartbeat(test_utils.BaseTestCase): if not heartbeat_side_effect: self.assertEqual(1, fake_ensure_connection.call_count) - self.assertEqual(2, fake_logger.debug.call_count) + self.assertEqual(3, fake_logger.debug.call_count) self.assertEqual(0, fake_logger.info.call_count) else: self.assertEqual(2, fake_ensure_connection.call_count) - self.assertEqual(2, fake_logger.debug.call_count) + self.assertEqual(3, fake_logger.debug.call_count) self.assertEqual(1, fake_logger.info.call_count) self.assertIn(mock.call(info, mock.ANY), fake_logger.info.mock_calls)