From a9f4994b52a458443976671abd19899b4fb7a088 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 16 Apr 2026 23:43:34 +0000 Subject: [PATCH] fix: swallow client-disconnect errors in JSON response writer Long-running endpoints like /api/delete can take 90+ seconds during Lidarr deletion workflows. If the browser times out or navigates away before the response is written, the wfile.write / end_headers calls raise ConnectionResetError / BrokenPipeError, producing a noisy traceback even though the server-side work completed successfully. Wrap the response write in a try/except for those two exceptions so the log stays clean when the client hangs up early. https://claude.ai/code/session_01CgFVz9atieqZfC5oiUnTKt --- app/webui.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/webui.py b/app/webui.py index be95e94..4ce6197 100644 --- a/app/webui.py +++ b/app/webui.py @@ -471,15 +471,21 @@ def log_message(self, format, *args): def _json_response(self, data, status=200, cookies=None): body = json.dumps(data).encode('utf-8') - self.send_response(status) - self.send_header('Content-Type', 'application/json') - self.send_header('Content-Length', len(body)) - self.send_header('Cache-Control', 'no-cache') - if cookies: - for cookie in cookies: - self.send_header('Set-Cookie', cookie) - self.end_headers() - self.wfile.write(body) + try: + self.send_response(status) + self.send_header('Content-Type', 'application/json') + self.send_header('Content-Length', len(body)) + self.send_header('Cache-Control', 'no-cache') + if cookies: + for cookie in cookies: + self.send_header('Set-Cookie', cookie) + self.end_headers() + self.wfile.write(body) + except (ConnectionResetError, BrokenPipeError): + # Client disconnected before we could reply (common for + # long-running endpoints like /api/delete). Server-side + # work already completed; nothing to do. + pass def _read_body(self): """Parse JSON request body. Returns dict or None on error."""