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')