From 85c7517ad036597b6432820121cae6f51ac2e96c 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 d7a3b2cb135..fa88a76b1a0 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): if request.destination[1] == CIRCUIT_ID_PORT: diff --git a/src/tribler/core/components/tunnel/tests/test_dispatcher.py b/src/tribler/core/components/tunnel/tests/test_dispatcher.py index c31c5cea7e2..e1cc953b0ae 100644 --- a/src/tribler/core/components/tunnel/tests/test_dispatcher.py +++ b/src/tribler/core/components/tunnel/tests/test_dispatcher.py @@ -94,6 +94,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