From a7c6699f6ac8efa57947fee746785ae9cd274f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Mon, 3 Mar 2025 13:51:40 +0100 Subject: [PATCH] Only log all ClientConnectionResets when returning logs (#5715) * Suppress all ClientConnectionReset when returning logs In #5358 we started suppressing ClientConnectionReset when logs are returned from the Journal Gateway and the client ends connection unexpectedly. The connection can be closed also when the headers are returned, so ignore also that error. Refs #5606 * Log ClientConnectionResetError as DEBUG instead of suppressing it --- supervisor/api/host.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/supervisor/api/host.py b/supervisor/api/host.py index 6e3399420..7a6488f74 100644 --- a/supervisor/api/host.py +++ b/supervisor/api/host.py @@ -255,16 +255,21 @@ class APIHost(CoreSysAttributes): response.content_type = CONTENT_TYPE_TEXT headers_returned = False async for cursor, line in journal_logs_reader(resp, log_formatter): - if not headers_returned: - if cursor: - response.headers["X-First-Cursor"] = cursor - response.headers["X-Accel-Buffering"] = "no" - await response.prepare(request) - headers_returned = True - # When client closes the connection while reading busy logs, we - # sometimes get this exception. It should be safe to ignore it. - with suppress(ClientConnectionResetError): + try: + if not headers_returned: + if cursor: + response.headers["X-First-Cursor"] = cursor + response.headers["X-Accel-Buffering"] = "no" + await response.prepare(request) + headers_returned = True await response.write(line.encode("utf-8") + b"\n") + except ClientConnectionResetError as err: + # When client closes the connection while reading busy logs, we + # sometimes get this exception. It should be safe to ignore it. + _LOGGER.debug( + "ClientConnectionResetError raised when returning journal logs: %s", + err, + ) except ConnectionResetError as ex: raise APIError( "Connection reset when trying to fetch data from systemd-journald."