Skip to content

Commit

Permalink
Merge pull request #7889 from xoriole/fix/7759-socket-error
Browse files Browse the repository at this point in the history
Fix network name is no longer available error
  • Loading branch information
xoriole authored Feb 7, 2024
2 parents 49d94dc + 0bb26ac commit 8b97f9e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,4 @@ def close(self, reason='unspecified'):

if self.transport:
self.transport.close()
self.transport = None
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_invalid_version(connection):
Test passing an invalid version to the socks5 server
"""
connection.data_received(unhexlify('040100'))
assert not connection.transport.connected
assert not connection.transport


def test_method_request(connection):
Expand Down
8 changes: 6 additions & 2 deletions src/tribler/core/components/tunnel/community/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions src/tribler/core/components/tunnel/tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b97f9e

Please sign in to comment.