diff options
author | Jordan <me@jordan.im> | 2022-04-02 23:48:51 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2022-04-02 23:48:51 -0700 |
commit | 4a10bfb093cef0f733ca49198b07495b64256666 (patch) | |
tree | f200397bf193e033e5ec5159a6f1662ad115ea76 | |
parent | ce815522804f9f472a22dd58999881e75d5b8961 (diff) | |
download | asn-4a10bfb093cef0f733ca49198b07495b64256666.tar.gz asn-4a10bfb093cef0f733ca49198b07495b64256666.zip |
asn: catch connection timeouts (bots) and other exceptions
-rwxr-xr-x | asn.py | 20 | ||||
m--------- | location-database | 0 |
2 files changed, 10 insertions, 10 deletions
@@ -32,22 +32,22 @@ class Listener: args=(conn,addr,), daemon=True).start() def _handler(self, conn, addr): - recv_data = conn.recv(1024) - if not recv_data: - conn.close() - + resp = '' try: + recv_data = conn.recv(1024) recv_data = str(recv_data, 'utf-8').strip() + except ConnectionResetError: + log.info(f'{addr[0]} connection reset') except UnicodeDecodeError: - resp = 'could not decode query to utf-8' + log.info(f'{addr[0]} could not decode to utf-8') + except Exception as err: + log.info(f'{addr[0]} {err}') else: log.info(f'{addr[0]} {recv_data}') - resp = self._get_announcements(recv_data) - if resp: - resp = self._pretty(resp) - else: - resp = '' + announcements = self._get_announcements(recv_data) + if announcements: + resp = self._pretty(announcements) finally: conn.sendall(bytes(resp, 'utf-8')) conn.shutdown(socket.SHUT_RDWR) diff --git a/location-database b/location-database -Subproject d5974438a2fcc46df8a864f17c600587ec32ded +Subproject 7ad544905562799b98ae99b3971d6db770ba0b4 |