stemserve: stay quiet on dropped client connections

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Sonnet 5.5 committed 2026-10-20 16:48:44 -07:00
1 parent 455d9a790c
commit 4277688a38
1 file changed
+10 -1
+10 -1
View File
@@ -490,6 +490,15 @@ def _format(query):
return "opus", min(OPUS_RATES, key=lambda r: abs(r - br)) return "opus", min(OPUS_RATES, key=lambda r: abs(r - br))
class QuietServer(ThreadingHTTPServer):
"""Browsers and proxies drop connections all the time; don't print a traceback for each."""
def handle_error(self, request, client_address):
if isinstance(sys.exc_info()[1], (ConnectionError, TimeoutError)):
return
super().handle_error(request, client_address)
def main(): def main():
if not os.path.isdir(STEMS_DIR): if not os.path.isdir(STEMS_DIR):
sys.exit(f"STEMS_DIR not found: {STEMS_DIR}") sys.exit(f"STEMS_DIR not found: {STEMS_DIR}")
@@ -497,7 +506,7 @@ def main():
INDEX.refresh() INDEX.refresh()
log(f"stemserve on :{PORT}, {INDEX.count} tracks in {STEMS_DIR}, ffmpeg={'yes' if FFMPEG else 'no'}, " log(f"stemserve on :{PORT}, {INDEX.count} tracks in {STEMS_DIR}, ffmpeg={'yes' if FFMPEG else 'no'}, "
f"token={'on' if TOKEN else 'off'}") f"token={'on' if TOKEN else 'off'}")
server = ThreadingHTTPServer(("0.0.0.0", PORT), Handler) server = QuietServer(("0.0.0.0", PORT), Handler)
server.daemon_threads = True server.daemon_threads = True
# As PID 1 in a container, SIGTERM is ignored unless handled; docker stop would hang. # As PID 1 in a container, SIGTERM is ignored unless handled; docker stop would hang.
signal.signal(signal.SIGTERM, lambda *_: sys.exit(0)) signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))