Skip to content

Commit a7c6699

Browse files
authored
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
1 parent fa7626f commit a7c6699

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

supervisor/api/host.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,21 @@ async def advanced_logs_handler(
255255
response.content_type = CONTENT_TYPE_TEXT
256256
headers_returned = False
257257
async for cursor, line in journal_logs_reader(resp, log_formatter):
258-
if not headers_returned:
259-
if cursor:
260-
response.headers["X-First-Cursor"] = cursor
261-
response.headers["X-Accel-Buffering"] = "no"
262-
await response.prepare(request)
263-
headers_returned = True
264-
# When client closes the connection while reading busy logs, we
265-
# sometimes get this exception. It should be safe to ignore it.
266-
with suppress(ClientConnectionResetError):
258+
try:
259+
if not headers_returned:
260+
if cursor:
261+
response.headers["X-First-Cursor"] = cursor
262+
response.headers["X-Accel-Buffering"] = "no"
263+
await response.prepare(request)
264+
headers_returned = True
267265
await response.write(line.encode("utf-8") + b"\n")
266+
except ClientConnectionResetError as err:
267+
# When client closes the connection while reading busy logs, we
268+
# sometimes get this exception. It should be safe to ignore it.
269+
_LOGGER.debug(
270+
"ClientConnectionResetError raised when returning journal logs: %s",
271+
err,
272+
)
268273
except ConnectionResetError as ex:
269274
raise APIError(
270275
"Connection reset when trying to fetch data from systemd-journald."

0 commit comments

Comments
 (0)