From 26fbe30f66e9ae23b8f6c57a18e5e3a13905f815 Mon Sep 17 00:00:00 2001 From: Leo Sin Date: Sun, 9 Jun 2024 15:01:46 -0400 Subject: [PATCH] chore: better handling for exceptions --- socks_router/router.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/socks_router/router.py b/socks_router/router.py index b0a1592..82bf0c8 100644 --- a/socks_router/router.py +++ b/socks_router/router.py @@ -334,7 +334,6 @@ def handle_request(self): self.logger.error(e) write_socket(self.connection, Socks5Reply(SOCKS_VERSION, Socks5ReplyType.GENERAL_SOCKS_SERVER_FAILURE)) self.state = Socks5State.CLOSED - raise e from None def exchange(self): exchange_loop(self.connection, self.remote, timeout=0) @@ -362,15 +361,18 @@ def handle(self): break case _ as unreachable: assert_never(unreachable) + except ConnectionResetError: + self.state = Socks5State.CLOSED except struct.error: # ignore: socket has nothing to read self.state = Socks5State.CLOSED except TimeoutError as e: self.logger.warning(e) self.state = Socks5State.CLOSED - # except Exception as e: - # self.logger.error(e) - # self.state = Socks5State.CLOSED + except Exception as e: + traceback.print_exc() + self.logger.error(e) + self.state = Socks5State.CLOSED def finish(self): if self.remote is not None: