Skip to content

Commit 380798e

Browse files
committed
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
1 parent 84b265a commit 380798e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

supervisor/api/host.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ 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
264258
# When client closes the connection while reading busy logs, we
265259
# sometimes get this exception. It should be safe to ignore it.
266260
with suppress(ClientConnectionResetError):
261+
if not headers_returned:
262+
if cursor:
263+
response.headers["X-First-Cursor"] = cursor
264+
response.headers["X-Accel-Buffering"] = "no"
265+
await response.prepare(request)
266+
headers_returned = True
267267
await response.write(line.encode("utf-8") + b"\n")
268268
except ConnectionResetError as ex:
269269
raise APIError(

0 commit comments

Comments
 (0)