Skip to content

Commit

Permalink
chore: better handling for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
leoslf committed Jun 9, 2024
1 parent dfb14f6 commit 26fbe30
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions socks_router/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 26fbe30

Please sign in to comment.