From 0bb26ac2f69bae6ef65a26a7067ea4e6ebcd2a7d Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 7 Feb 2024 14:19:55 +0100 Subject: [PATCH] Fix dispatcher on_socks5_tcp_data when transport is none --- .../core/components/tunnel/community/dispatcher.py | 8 ++++++-- .../core/components/tunnel/tests/test_dispatcher.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tribler/core/components/tunnel/community/dispatcher.py b/src/tribler/core/components/tunnel/community/dispatcher.py index 4799da3f0d2..b37466467aa 100644 --- a/src/tribler/core/components/tunnel/community/dispatcher.py +++ b/src/tribler/core/components/tunnel/community/dispatcher.py @@ -93,9 +93,13 @@ async def on_socks5_tcp_data(self, tcp_connection, destination, request): self._logger.info('Failed to get HTTP response using tunnels: %s', e) return + transport = tcp_connection.transport + if not transport: + return + if response: - tcp_connection.transport.write(response) - tcp_connection.transport.close() + transport.write(response) + transport.close() def select_circuit(self, connection, request): def add_data_if_result(result_func, connection=connection.udp_connection, request=request): diff --git a/src/tribler/core/components/tunnel/tests/test_dispatcher.py b/src/tribler/core/components/tunnel/tests/test_dispatcher.py index 9584844d692..fadbecd7794 100644 --- a/src/tribler/core/components/tunnel/tests/test_dispatcher.py +++ b/src/tribler/core/components/tunnel/tests/test_dispatcher.py @@ -96,6 +96,14 @@ async def test_on_socks_in_tcp(dispatcher): tcp_connection.transport.write.assert_called_once_with(b'test') +async def test_on_socks5_tcp_data_with_transport_none(dispatcher): + tcp_connection = Mock(transport=None) + dispatcher.set_socks_servers([tcp_connection.socksserver]) + + dispatcher.tunnels.perform_http_request = Mock(return_value=succeed(b'test')) + await dispatcher.on_socks5_tcp_data(tcp_connection, ("0.0.0.0", 1024), b'') + + def test_circuit_dead(dispatcher, mock_circuit): """ Test whether the correct peers are removed when a circuit breaks