More friendly error reporting for peername errors (#7716)

This commit is contained in:
Earle Lowe 2021-07-22 09:05:31 -07:00 committed by GitHub
parent d3599da0a0
commit 18708e2bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -278,6 +278,11 @@ class ChiaServer:
error_stack = traceback.format_exc()
self.log.error(f"Exception {e}, exception Stack: {error_stack}")
close_event.set()
except ValueError as e:
if connection is not None:
await connection.close(self.invalid_protocol_ban_seconds, WSCloseCode.PROTOCOL_ERROR, Err.UNKNOWN)
self.log.warning(f"{e} - closing connection")
close_event.set()
except Exception as e:
if connection is not None:
await connection.close(ws_close_code=WSCloseCode.PROTOCOL_ERROR, error=Err.UNKNOWN)

View File

@ -56,7 +56,7 @@ class WSChiaConnection:
peername = self.ws._writer.transport.get_extra_info("peername")
if peername is None:
raise ValueError(f"Was not able to get peername from {self.ws_witer} at {self.peer_host}")
raise ValueError(f"Was not able to get peername from {self.peer_host}")
connection_port = peername[1]
self.peer_port = connection_port