Township web UI: suppress BrokenPipe/ConnReset from aborted requests

Browsers routinely abort media (video seek/scrub) and SSE connections
mid-response, which surfaced as BrokenPipeError/ConnectionResetError
tracebacks spamming the terminal. Swallow these in the request handler's
handle_one_request() and finish() so they're ignored cleanly.
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
parent df1c0032
...@@ -3806,6 +3806,21 @@ async function pollJob(){ ...@@ -3806,6 +3806,21 @@ async function pollJob(){
class _Handler(http.server.BaseHTTPRequestHandler): class _Handler(http.server.BaseHTTPRequestHandler):
def log_message(self, fmt, *args): pass # suppress access log def log_message(self, fmt, *args): pass # suppress access log
def handle_one_request(self):
# Browsers routinely abort media (video seek/scrub) and SSE
# connections mid-response; that surfaces as BrokenPipe/ConnReset.
# Swallow those so they don't spam the terminal with tracebacks.
try:
super().handle_one_request()
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
self.close_connection = True
def finish(self):
try:
super().finish()
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
pass
def _send(self, code, ctype, body): def _send(self, code, ctype, body):
if isinstance(body, str): body = body.encode() if isinstance(body, str): body = body.encode()
self.send_response(code) self.send_response(code)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment