Skip to content

Commit

Permalink
Suppress all ClientConnectionReset when returning logs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sairon committed Mar 3, 2025
1 parent 84b265a commit 380798e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions supervisor/api/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ async def advanced_logs_handler(
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):
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 ConnectionResetError as ex:
raise APIError(
Expand Down

0 comments on commit 380798e

Please sign in to comment.