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,17 +127,26 @@ class RangeHandler(SimpleHTTPRequestHandler):
return _LimitedReader(f, length)
def copyfile(self, source, outputfile):
if isinstance(source, _LimitedReader):
remaining = source.remaining
while remaining > 0:
chunk = source.read(min(64 * 1024, remaining))
if not chunk:
break
outputfile.write(chunk)
remaining -= len(chunk)
source.close()
else:
super().copyfile(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):
try:
remaining = source.remaining
while remaining > 0:
chunk = source.read(min(64 * 1024, remaining))
if not chunk:
break
outputfile.write(chunk)
remaining -= len(chunk)
finally:
source.close()
else:
super().copyfile(source, outputfile)
except (BrokenPipeError, ConnectionResetError):
pass
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