From b0512725f65b339eeee3cb1e8cbaeb3c86de2ea1 Mon Sep 17 00:00:00 2001 From: Bryan Shelton Date: Sun, 27 May 2018 07:54:37 -0700 Subject: [PATCH] Handle librabbitmq fileno socket not connected raising ValueError (#878) * Handle librabbitmq fileno socket not connected raises ValueError * Test client objects set to None * Assert that librabbitmq's conn.fileno is called --- kombu/transport/librabbitmq.py | 2 +- t/unit/transport/test_librabbitmq.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kombu/transport/librabbitmq.py b/kombu/transport/librabbitmq.py index fbe29d1b..c61943e1 100644 --- a/kombu/transport/librabbitmq.py +++ b/kombu/transport/librabbitmq.py @@ -146,7 +146,7 @@ class Transport(base.Transport): channel.connection = None try: os.close(connection.fileno()) - except OSError: + except (OSError, ValueError): pass connection.channels.clear() connection.callbacks.clear() diff --git a/t/unit/transport/test_librabbitmq.py b/t/unit/transport/test_librabbitmq.py index 26dbfbcd..42829d96 100644 --- a/t/unit/transport/test_librabbitmq.py +++ b/t/unit/transport/test_librabbitmq.py @@ -125,6 +125,18 @@ class test_Transport(lrmqCase): self.T._collect(conn) close.assert_called_with(conn.fileno()) + def test_collect__with_fileno_raising_value_error(self): + conn = Mock(name='connection') + conn.channels = {1: Mock(name='chan1'), 2: Mock(name='chan2')} + with patch('os.close') as close: + self.T.client = self.client + conn.fileno.side_effect = ValueError("Socket not connected") + self.T._collect(conn) + close.assert_not_called() + conn.fileno.assert_called_with() + assert self.client.drain_events is None + assert self.T.client is None + def test_register_with_event_loop(self): conn = Mock(name='conn') loop = Mock(name='loop')