Skip to content

Commit

Permalink
Merge pull request #7912 from xoriole/fix/7759-socket-error-7.13
Browse files Browse the repository at this point in the history
Fix network name is no longer available error on 7.13
  • Loading branch information
xoriole authored Feb 20, 2024
2 parents a91f986 + 85c7517 commit a2fda3d
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):
if request.destination[1] == CIRCUIT_ID_PORT:
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 @@ -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
Expand Down

0 comments on commit a2fda3d

Please sign in to comment.