Skip to content

Commit

Permalink
Suppress ClientConnectionResetError when returning logs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sairon committed Oct 17, 2024
1 parent 96df335 commit aa93edd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions supervisor/api/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -260,7 +260,10 @@ async def advanced_logs_handler(
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."
Expand Down

0 comments on commit aa93edd

Please sign in to comment.