diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py index 11821f8cf..8ac107808 100644 --- a/oslo_messaging/_drivers/impl_rabbit.py +++ b/oslo_messaging/_drivers/impl_rabbit.py @@ -810,7 +810,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 1a6a5e3bc..dbd1ecada 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)