fix(transmission): retry temporary status lookup failures (#1706)

A brief RPC outage currently fails the download immediately. Retry
Transmission connection errors, including timeouts, with the shared
helper's default three attempts and exponential backoff. Authentication
and other RPC errors still fail immediately.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Transmission status checks now retry after connection errors, reducing
transient failures when retrieving torrent information.
* **Improvements**
* Retry handling can now include additional exception types where
needed.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Ihar Hrachyshka authored and GitHub committed 2026-11-13 00:53:47 -05:00
1 parent 99275a2ddb
commit 90ac049ae7
2 files changed
+17 -2

No files matched your search

+6 -1
View File
@@ -49,6 +49,8 @@ def with_retry(
base_delay: float = 1.0,
max_delay: float = 10.0,
jitter: float = 0.5,
*,
extra_exceptions: tuple[type[Exception], ...] = (),
) -> Callable[[Callable[..., T]], Callable[..., T]]:
"""Retry API calls with exponential backoff.
@@ -57,6 +59,7 @@ def with_retry(
base_delay: Initial delay in seconds (default 1.0)
max_delay: Maximum delay cap in seconds (default 10.0)
jitter: Random jitter factor 0-1 to add to delay (default 0.5)
extra_exceptions: Client-library exceptions that also allow a retry
Retries on:
- Connection errors
@@ -69,6 +72,8 @@ def with_retry(
"""
retryable_exceptions = RETRYABLE_EXCEPTIONS + extra_exceptions
def decorator(func: Callable[..., T]) -> Callable[..., T]:
@wraps(func)
def wrapper(*args: object, **kwargs: object) -> T:
@@ -82,7 +87,7 @@ def with_retry(
if e.response is not None and e.response.status_code < _MIN_RETRYABLE_STATUS:
raise
last_exception = e
except RETRYABLE_EXCEPTIONS as e:
except retryable_exceptions as e:
last_exception = e
if attempt < max_attempts:
+11 -1
View File
@@ -9,12 +9,15 @@ import importlib
from contextlib import contextmanager, suppress
from typing import TYPE_CHECKING, Protocol, TypeGuard
from transmission_rpc.error import TransmissionConnectError
from shelfmark.core.config import config
from shelfmark.core.logger import setup_logger
from shelfmark.download.clients import (
DownloadClient,
DownloadStatus,
register_client,
with_retry,
)
from shelfmark.download.clients._coercion import (
coerce_optional_float,
@@ -37,6 +40,8 @@ except ImportError:
if TYPE_CHECKING:
from collections.abc import Iterator
from transmission_rpc import Torrent
logger = setup_logger(__name__)
_SEEDING_PROGRESS_PERCENT = 100
@@ -294,6 +299,11 @@ class TransmissionClient(DownloadClient):
else:
return torrent_hash
@with_retry(extra_exceptions=(TransmissionConnectError,))
def _get_torrent(self, download_id: str) -> Torrent:
"""Allow transient RPC outages to recover before reporting a failed download."""
return self._client.get_torrent(download_id)
def get_status(self, download_id: str) -> DownloadStatus:
"""Get torrent status by hash.
@@ -305,7 +315,7 @@ class TransmissionClient(DownloadClient):
"""
try:
torrent = self._client.get_torrent(download_id)
torrent = self._get_torrent(download_id)
# Transmission status values:
# 0: stopped