GeezerVison is showing github.com — fix(relay): keep recover() going past a transient entry failure · CortexLM/hypertrain@43cfcf7
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/hypertrain/relay/core.py +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
8 | 8 | from __future__ import annotations |
9 | 9 |
|
10 | 10 | import hashlib |
| 11 | +import logging |
11 | 12 | import secrets |
12 | 13 | from collections.abc import AsyncIterator, Awaitable, Callable |
13 | 14 | from contextlib import asynccontextmanager |
@@ -508,6 +509,12 @@ def pending( |
508 | 509 | except httpx.HTTPError: |
509 | 510 | # Exact failure recorded by complete; custody remains retrievable. |
510 | 511 | continue |
| 512 | + except (OSError, ValueError) as error: |
| 513 | + # Retriable (TimeoutError, ValidationError, SignatureError, I/O): record |
| 514 | + # nothing terminal so a later recover() tries again; never log payloads. |
| 515 | + logging.getLogger(__name__).warning( |
| 516 | + "relay recover deferred: %s", type(error).__name__ |
| 517 | + ) |
511 | 518 |
|
512 | 519 | def _scope(self, record: UploadRecord, hashes: list[str]) -> list[Pin]: |
513 | 520 | if ( |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/relay/test_lifecycle_v2.py +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -799,3 +799,28 @@ async def scenario() -> None: |
799 | 799 | assert completed.count(rotten.digest()) == 0 |
800 | 800 |
|
801 | 801 | anyio.run(scenario) |
| 802 | + |
| 803 | + |
| 804 | +def test_recover_retries_after_transient_error( |
| 805 | + tmp_path: Path, caplog: pytest.LogCaptureFixture |
| 806 | +) -> None: |
| 807 | + # Given: the first journal entry's backing read times out once. |
| 808 | + async def scenario() -> None: |
| 809 | + async with httpx.AsyncClient() as client: |
| 810 | + rig = Rig(tmp_path, client) |
| 811 | + slow, honest = await interrupted_pair(rig) |
| 812 | + original = rig.store.get |
| 813 | + failing_get(rig, hashlib.sha256(b"abc").hexdigest(), TimeoutError()) |
| 814 | + relay = rig.new_relay() |
| 815 | + await relay.recover() |
| 816 | + state = await relay.state() |
| 817 | + assert state.uploads[honest.digest()].receipt is not None |
| 818 | + assert state.uploads[slow.digest()].forward_error is None |
| 819 | + assert "TimeoutError" in caplog.text |
| 820 | + # When: the backing recovers and recovery runs again. |
| 821 | + rig.store.get = original # type: ignore[method-assign] |
| 822 | + await relay.recover() |
| 823 | + # Then: the transient entry is retried and completes. |
| 824 | + assert (await relay.state()).uploads[slow.digest()].receipt is not None |
| 825 | + |
| 826 | + anyio.run(scenario) |