fix(downloader): outlast network outages and harden segment merges

Outage-only retry budget, fail fast on a full disk, rnet read_timeout from config, fixed-size shared range parts, Windows-safe segment deletes, merge benchmark.
This commit is contained in:
imSp4rky
2026-11-23 13:43:38 -07:00
parent 138782f38b
commit 91fbe67fa6
14 changed files with 708 additions and 55 deletions
+42 -14
View File
@@ -20,6 +20,7 @@ real spawns stay fast.
import importlib
import multiprocessing
import os
import threading
import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -98,6 +99,27 @@ def clear_cancel():
dl.DOWNLOAD_CANCELLED.clear()
def die_without_result(queue, kwargs):
os._exit(3)
def run_mp(urls, tmp_path):
for _ in dl.download_multiprocess(
urls=urls,
output_dir=tmp_path,
filename="seg_{i:04}.bin",
headers=None,
cookies=None,
proxy=None,
max_workers=2,
adaptive=False,
spec={"kind": "none"},
processes=2,
debug_logger=None,
):
pass
def url(srv, path):
return f"http://127.0.0.1:{srv.server_address[1]}{path}"
@@ -127,20 +149,26 @@ def test_multiprocess_child_crash_raises(server, tmp_path):
good = {"url": url(server, "/seg/0.bin")}
bad = {"nourl": True}
with pytest.raises(RuntimeError):
for _ in dl.download_multiprocess(
urls=[good, bad],
output_dir=tmp_path,
filename="seg_{i:04}.bin",
headers=None,
cookies=None,
proxy=None,
max_workers=2,
adaptive=False,
spec={"kind": "none"},
processes=2,
debug_logger=None,
):
pass
run_mp([good, bad], tmp_path)
def test_multiprocess_child_death_raises(tmp_path, monkeypatch):
monkeypatch.setattr(dl, "mp_worker", die_without_result)
raised: list[BaseException] = []
def drive():
try:
run_mp([{"url": "http://127.0.0.1:1/a"}, {"url": "http://127.0.0.1:1/b"}], tmp_path)
except BaseException as exc:
raised.append(exc)
thread = threading.Thread(target=drive, daemon=True)
thread.start()
thread.join(timeout=30)
assert not thread.is_alive()
assert len(raised) == 1 and isinstance(raised[0], RuntimeError)
assert "died without result" in str(raised[0])
def test_multiprocess_cancel_terminates_children(server, tmp_path):