From 6f196c9deae1c9c03a12fe2162ac9cb3362983fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Mon, 21 Oct 2024 10:11:22 +0200 Subject: [PATCH] Suppress ClientConnectionResetError when returning logs (#5358) When client requests (or more often follows) some busy logs and closes the connection while the StreamWriter tries to write into it, an exception is raised. This should be harmless, and unless there's another way to handle this gracefully (I'm not aware of), then it should be safe to ignore the exception in this context. --- supervisor/api/host.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/supervisor/api/host.py b/supervisor/api/host.py index 0ba429532..81739f0bb 100644 --- a/supervisor/api/host.py +++ b/supervisor/api/host.py @@ -4,7 +4,7 @@ import asyncio from contextlib import suppress import logging -from aiohttp import web +from aiohttp import ClientConnectionResetError, web from aiohttp.hdrs import ACCEPT, RANGE import voluptuous as vol from voluptuous.error import CoerceInvalid @@ -260,7 +260,10 @@ class APIHost(CoreSysAttributes): response.headers["X-First-Cursor"] = cursor await response.prepare(request) headers_returned = True - await response.write(line.encode("utf-8") + b"\n") + # When client closes the connection while reading busy logs, we + # sometimes get this exception. It should be safe to ignore it. + with suppress(ClientConnectionResetError): + await response.write(line.encode("utf-8") + b"\n") except ConnectionResetError as ex: raise APIError( "Connection reset when trying to fetch data from systemd-journald."