Commit d70c3ee7 by PLN (Algolia)

fix(armada/serve): swallow client-disconnect on media Range seek

copyfile() threw BrokenPipeError/ConnectionResetError (Errno 104) when a
browser aborts/seeks a Range request mid-stream — normal for <audio>
scrubbing, but it spammed a traceback. Wrap both copy branches and close
the file handle in a finally. Verified: mid-stream abort leaves no
traceback and the server keeps serving (206 follow-up OK).
parent 92487ebe
...@@ -127,7 +127,13 @@ class RangeHandler(SimpleHTTPRequestHandler): ...@@ -127,7 +127,13 @@ class RangeHandler(SimpleHTTPRequestHandler):
return _LimitedReader(f, length) return _LimitedReader(f, length)
def copyfile(self, source, outputfile): def copyfile(self, source, outputfile):
# A client that seeks/aborts a media Range request mid-stream raises
# BrokenPipeError/ConnectionResetError on the next write. That's normal
# for <audio> scrubbing, not a failure — swallow it (no traceback), but
# still close the file handle.
try:
if isinstance(source, _LimitedReader): if isinstance(source, _LimitedReader):
try:
remaining = source.remaining remaining = source.remaining
while remaining > 0: while remaining > 0:
chunk = source.read(min(64 * 1024, remaining)) chunk = source.read(min(64 * 1024, remaining))
...@@ -135,9 +141,12 @@ class RangeHandler(SimpleHTTPRequestHandler): ...@@ -135,9 +141,12 @@ class RangeHandler(SimpleHTTPRequestHandler):
break break
outputfile.write(chunk) outputfile.write(chunk)
remaining -= len(chunk) remaining -= len(chunk)
finally:
source.close() source.close()
else: else:
super().copyfile(source, outputfile) super().copyfile(source, outputfile)
except (BrokenPipeError, ConnectionResetError):
pass
class _LimitedReader: class _LimitedReader:
......
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