From b391e8478f4a49e71eb43bc69d84258f91318821 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Tue, 12 Sep 2023 00:23:54 +0200 Subject: [PATCH] Version 2.3.8 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/bettercap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pwnagotchi/bettercap.py b/pwnagotchi/bettercap.py index d1cf0cbb..bd7b7c50 100644 --- a/pwnagotchi/bettercap.py +++ b/pwnagotchi/bettercap.py @@ -57,6 +57,9 @@ class Client(object): # logging.debug("Other exception (%s) with parameter %s", e, s) async with websockets.connect(s, ping_interval=60, ping_timeout=90) as ws: + # After the websocket connection is opened, loop waiting for messages + # Moved the websocket connection before the loop to avoid runaway websocket + # connections that were exhausting all possible TCP ports (ephemeral port exhaustion) while True: try: async for msg in ws: @@ -66,12 +69,16 @@ class Client(object): logging.debug("Error while parsing event (%s)", ex) except websockets.exceptions.ConnectionClosedError: logging.error("Lost websocket connection. Reconnecting...") + continue except websockets.exceptions.WebSocketException as wex: logging.error("Websocket exception (%s)", wex) + continue except OSError as e: logging.error("Websocket OSError exception (%s) with parameter %s", e, s) + continue except Exception as e: logging.error("Other exception (%s) with parameter %s", e, s) + continue def run(self, command, verbose_errors=True): for _ in range(0,2):