fix: retry _poll_task on transient 599 instead of aborting immediately
DirSize for large directories (e.g. /docker, 8441 folders, 46832 files) takes ~800ms to compute. While running, status returns intermediate progress (finished=false). But on the very first poll the task can return 599 transiently (task just started, not yet available). Previously _poll_task caught any SynologyError and returned immediately, making dir_size always fail on the first 599. Fix: treat 599 as a transient condition and continue polling. Give up only after 5 consecutive 599 responses. All other error codes remain immediately fatal. Investigation confirmed with test_dirsize_md5.py: - /test-mcp (2937 B): finished=true at 0ms - /docker (3.9 GB, 46832 files): finished=false at 35ms, finished=true at 789ms Tests: 2 new cases (retry-succeeds, 5x-599-gives-up) → 95 total Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -86,6 +86,7 @@ def register_filestation(
|
||||
delay = 0.2
|
||||
elapsed = initial_delay
|
||||
timeout = 60.0
|
||||
consecutive_599 = 0
|
||||
|
||||
if initial_delay > 0:
|
||||
await asyncio.sleep(initial_delay)
|
||||
@@ -98,11 +99,19 @@ def register_filestation(
|
||||
version=version,
|
||||
params={"taskid": taskid},
|
||||
)
|
||||
consecutive_599 = 0
|
||||
except _SynologyError as e:
|
||||
return False, f"Error: {e}"
|
||||
|
||||
if status_data.get("finished"):
|
||||
return True, status_data
|
||||
if e.code == 599:
|
||||
# 599 can be transient (task just started, not yet available).
|
||||
# Retry up to 5 times before giving up.
|
||||
consecutive_599 += 1
|
||||
if consecutive_599 >= 5:
|
||||
return False, f"Error: {e}"
|
||||
else:
|
||||
return False, f"Error: {e}"
|
||||
else:
|
||||
if status_data.get("finished"):
|
||||
return True, status_data
|
||||
|
||||
if elapsed >= timeout:
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user