From a359ff2263d301d03a5c9fd4c9f99bba3e264c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Sat, 3 Jul 2021 21:48:38 +0200 Subject: [PATCH] Fixing tunnel & client for mac --- client-py3/full/src/UDSClientLauncher.py | 15 +++++++++++++-- tunnel-server/src/uds_tunnel/proxy.py | 8 +++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client-py3/full/src/UDSClientLauncher.py b/client-py3/full/src/UDSClientLauncher.py index e7bd2e6d..42c53c0a 100644 --- a/client-py3/full/src/UDSClientLauncher.py +++ b/client-py3/full/src/UDSClientLauncher.py @@ -22,8 +22,19 @@ class UdsApplication(QtWidgets.QApplication): self.lastWindowClosed.connect(self.closeTunnels) # type: ignore def cleanTunnels(self) -> None: - for k in [i for i, tunnel in enumerate(self.tunnels) if tunnel.poll() is not None]: - del self.tunnels[k] + def isRunning(p: subprocess.Popen): + try: + if p.poll() is None: + return True + except Exception as e: + logger.debug('Got error polling subprocess: %s', e) + return False + + for k in [i for i, tunnel in enumerate(self.tunnels) if not isRunning(tunnel)]: + try: + del self.tunnels[k] + except Exception as e: + logger.debug('Error closing tunnel: %s', e) def closeTunnels(self) -> None: logger.debug('Closing remaining tunnels') diff --git a/tunnel-server/src/uds_tunnel/proxy.py b/tunnel-server/src/uds_tunnel/proxy.py index 85a8dcda..7837f7e0 100644 --- a/tunnel-server/src/uds_tunnel/proxy.py +++ b/tunnel-server/src/uds_tunnel/proxy.py @@ -40,6 +40,7 @@ from . import consts if typing.TYPE_CHECKING: from multiprocessing.managers import Namespace + import curio.io logger = logging.getLogger(__name__) @@ -92,7 +93,7 @@ class Proxy: Proxy._getUdsUrl(cfg, ticket, 'stop', {'sent': str(counter.sent), 'recv': str(counter.recv)}) # Ignore results @staticmethod - async def doProxy(source, destination, counter: stats.StatsSingleCounter) -> None: + async def doProxy(source: 'curio.io.Socket', destination: 'curio.io.Socket', counter: stats.StatsSingleCounter) -> None: try: while True: data = await source.recv(consts.BUFFER_SIZE) @@ -101,8 +102,9 @@ class Proxy: await destination.sendall(data) counter.add(len(data)) except Exception: - # Connection broken - logger.info('CONNECTION LOST FROM %s to %s', source, destination) + # Connection broken, same result as closed for us (even log is removed) + # logger.info('CONNECTION LOST FROM %s to %s', source.getsockname(), destination.getpeername()) + pass # Method responsible of proxying requests