fix(ops): avoid truncating stockplatform runtime readback
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 1m3s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
AWOOOI Harbor 110 Local Repair / workflow-shape (push) Successful in 1s
AWOOOI Harbor 110 Local Repair / harbor-110-local-repair (push) Successful in 26s

This commit is contained in:
Your Name
2026-07-02 19:11:10 +08:00
parent 9302933a95
commit a13038db87
2 changed files with 37 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ _DEFAULT_BASE_URL = "https://stock.wooo.work"
_DEFAULT_TIMEOUT_SECONDS = 4.0
_DEFAULT_DATA_ENDPOINT_TIMEOUT_SECONDS = 10.0
_DEFAULT_PROBE_ATTEMPTS = 2
_MAX_READBACK_BODY_BYTES = 500_000
Probe = Callable[[str, float], dict[str, Any]]
@@ -650,10 +651,12 @@ def _http_probe(url: str, timeout_seconds: float) -> dict[str, Any]:
)
try:
with urllib.request.urlopen(request, timeout=timeout_seconds) as response:
body = response.read(8192).decode("utf-8", "replace")
body = response.read(_MAX_READBACK_BODY_BYTES).decode(
"utf-8", "replace"
)
return {"http_status": response.status, "body": body, "error": ""}
except urllib.error.HTTPError as exc:
body = exc.read(2048).decode("utf-8", "replace")
body = exc.read(_MAX_READBACK_BODY_BYTES).decode("utf-8", "replace")
return {"http_status": exc.code, "body": body, "error": ""}
except Exception as exc: # noqa: BLE001 - readback must fail closed.
return {"http_status": None, "body": "", "error": _error_text(exc)}