From 154fcd803b3fe9c6fe362a1706bdcd43869dc05b Mon Sep 17 00:00:00 2001 From: Will Miao Date: Fri, 26 Jun 2026 14:19:37 +0800 Subject: [PATCH] fix(aria2): disable fsync and relax RPC timeouts to prevent aria2 freeze on large files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aria2 default --fsync=true calls fsync() after each write, which blocks the entire single-threaded process on large files under Docker overlay. Add --fsync=false to eliminate this blocking source. Relax aiohttp session timeout: total=30 → sock_connect=10, sock_read=60 so that transient I/O delays don't cut off legitimate tellStatus RPCs. Increase retry params (4 attempts, 3s delay) to give aria2 more recovery time when blocked on synchronous I/O. --- py/services/aria2_downloader.py | 7 +++++-- tests/services/test_aria2_downloader.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/py/services/aria2_downloader.py b/py/services/aria2_downloader.py index 617cdb9d..0ab07a19 100644 --- a/py/services/aria2_downloader.py +++ b/py/services/aria2_downloader.py @@ -138,7 +138,7 @@ class Aria2Downloader: self._transfers.pop(download_id, None) async def _get_status_with_retry( - self, download_id: str, *, max_retries: int = 3, retry_delay: float = 1.0 + self, download_id: str, *, max_retries: int = 4, retry_delay: float = 3.0 ) -> Optional[Dict[str, Any]]: """Call get_status with retry for transient RPC failures. @@ -510,6 +510,7 @@ class Aria2Downloader: "--continue=true", "--daemon=false", "--quiet=true", + "--fsync=false", f"--stop-with-process={os.getpid()}", ] @@ -649,7 +650,9 @@ class Aria2Downloader: if self._rpc_session is None or self._rpc_session.closed: async with self._rpc_session_lock: if self._rpc_session is None or self._rpc_session.closed: - timeout = aiohttp.ClientTimeout(total=30) + timeout = aiohttp.ClientTimeout( + total=None, sock_connect=10, sock_read=60 + ) self._rpc_session = aiohttp.ClientSession(timeout=timeout) return self._rpc_session diff --git a/tests/services/test_aria2_downloader.py b/tests/services/test_aria2_downloader.py index 6c300fb8..c61b3778 100644 --- a/tests/services/test_aria2_downloader.py +++ b/tests/services/test_aria2_downloader.py @@ -410,7 +410,7 @@ async def test_get_status_with_retry_raises_after_all_retries_exhausted(monkeypa await downloader._get_status_with_retry("dummy") msg = str(exc_info.value) - assert "after 3 attempts" in msg + assert "after 4 attempts" in msg assert "connection reset" in msg