diff --git a/haproxyspoa/spoa_server.py b/haproxyspoa/spoa_server.py index cc079bc..384fccd 100644 --- a/haproxyspoa/spoa_server.py +++ b/haproxyspoa/spoa_server.py @@ -66,7 +66,7 @@ async def handle_haproxy_disconnect(self, frame: Frame): async def handle_hello_handshake(self, frame: Frame): capabilities = AgentCapabilities() - self.logger.info(f"Received `hello handshake`, responding with agent capabilities of: '{capabilities}'") + self.logger.debug(f"Received `hello handshake`, responding with agent capabilities of: '{capabilities}'") agent_hello_frame = AgentHelloFrame( payload=AgentHelloPayload( capabilities=capabilities, @@ -94,7 +94,11 @@ def wrapper(*args, **kwargs): async def handle_connection(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter): conn = SpoaConnection(writer, self.handlers) - haproxy_hello_frame = await Frame.read_frame(reader) + try: + haproxy_hello_frame = await Frame.read_frame(reader) + except asyncio.exceptions.IncompleteReadError: + conn.logger.debug("Incomplete read, exiting") + return if not haproxy_hello_frame.headers.is_haproxy_hello(): conn.logger.error(f""" @@ -106,11 +110,15 @@ async def handle_connection(self, reader: asyncio.StreamReader, writer: asyncio. await conn.handle_hello_handshake(haproxy_hello_frame) if HaproxyHelloPayload(haproxy_hello_frame.payload).healthcheck(): - conn.logger.info("Health check, immediately disconnecting") + conn.logger.debug("Health check, immediately disconnecting") return while True: - frame = await Frame.read_frame(reader) + try: + frame = await Frame.read_frame(reader) + except Exception as e: + conn.logger.debug("Exception %s during reading frame.", e) + return if frame.headers.is_haproxy_disconnect(): await conn.handle_haproxy_disconnect(frame)