Repository navigation
feat(k8s): retry cleanup API calls with a per-request timeout - #71
Conversation
Cleanup (prunePods / pruneSecrets) issued a single untimed request per resource. A transient ClusterIP -> apiserver blip could pin the TCP connection to a dead backend via conntrack, hanging the connect until the kernel exhausted SYN retries (~127s) and failing a job whose test steps had all passed (vllm-ascend 11-09, twenty-one jobs). Wrap every cleanup list/delete call in retryK8sApiCall so each attempt is bounded by the default 15s timeout and reopens a fresh connection, and accept an injectable client + retry options for unit testing.
Welcome To opensourceways CommunityHey @wyhhai , thanks for your contribution to the community. Bot Usage ManualI'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. Contact GuideIf you have any questions, please contact the SIG: infratructure , |
CLA Signature Passwyhhai, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
Linking Issue Notice@wyhhai , the pull request must be linked to at least one issue. |
|
/check-issue |
|
谢谢,改动方向和描述一致:cleanup 里的 list/delete 都走
下面几项建议按风险从高到低处理。 1. 重试 delete 可能因 404 反而失败(P0)
#2656 里记录的单向丢包特征(只有去程 SYN、没有 REJECT)让这个场景并非纯理论。 建议:delete 的包装里把 404 当作成功,例如 await retryK8sApiCall(...).catch(err => {
if ((err as { code?: number }).code === 404) return
throw err
})或者给 2. Prepare 阶段的
|
- Treat 404 on delete as success: a request that timed out client-side may already have been applied server-side, so the retry legitimately observes NotFound and must not fail an otherwise green job. - Raise the cleanup attempt budget to 6 (~141s) to cover the ~127s kernel SYN-retry window seen on the HK CI nodes. - Log the error code instead of "[object Object]" for plain-object errors. - Remove deleteSecret(), which lost its last caller when the delete path was inlined for retrying.
CLA Signature Passwyhhai, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
|
感谢 review,四条都处理了(commit c508f44)。 1. delete 收到 404 反而失败(P0)—— 已修
原先固化了「404 = 失败」的那个用例已改写,并保留一个反向用例(400 仍然抛错)。 2. Prepare 阶段 3. 重试预算 —— 已提到 6 次 4. 细节 —— 全部采纳
本地验证: |
Linking Issue Notice@wyhhai , the pull request must be linked to at least one issue. |
|
/check-issue |
Prepare-stage createJobPod was not covered by the cleanup retry work, yet 3 of the 10 ETIMEDOUT events observed on the HK CI nodes happened there. Creates cannot simply be retried: when the first attempt succeeds and only the response is lost, the retry gets 409 AlreadyExists. Treat that as success by reading the object back, which keeps the call idempotent.
|
补一下你提的第 2 点:Prepare 阶段的 create 也覆盖了(commit a0b96f4),不再是 TODO。 改动:
新增 5 个用例:
本地验证: 剩下的唯一 Scope 项是「cleanup 改成 best-effort(warn + exit 0)」,因为它改变失败语义,仍建议单独 PR。 |
CLA Signature Passwyhhai, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
Linking Issue Notice@wyhhai , the pull request must be linked to at least one issue. |
|
LGTM,剩余两点小问题:
其余改动本地复验过: |
The 409 read-back was a bare, untimed call, which reintroduced the exact hang this PR removes whenever the link is still blackholed. Route it through retryK8sApiCall with the same policy as the create.
|
两点都改了(commit 7d471bf)。 1. 409 回读包上重试 —— 说得对,这是我漏掉的 补了用例 2. 正文脱敏 —— 已改 本地复验: |
CLA Signature Passwyhhai, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
|
/check-issue |
|
/lgtm |
Label Command Feedback
|
Background
Cleanup (
Stop containers→cleanupJob()→prunePods()/pruneSecrets()) used to issue one untimed, un-retried request per resource. When the node-local ClusterIP → managed apiserver path has a transient blip, kube-proxy/conntrack can pin the connection to a dead backend: the SYN is blackholed and the process hangs until the kernel exhausts SYN retries (~127s), then fails withconnect ETIMEDOUT.This is not theoretical:
vllm-project/vllm-ascend/actions/runs/42573365617/job/129015567064— all seven business steps succeeded, only the post-jobStop containersfailed after 129.9s withFetchError ... https://<apiserver>/api/v1/namespaces/<namespace>/pods ... connect ETIMEDOUT.listNamespacedSecretanddeleteNamespacedPod(131s / 133s).isAuthPermissionsOK, which already retries since feat(k8s): retry transient k8s API failures in auth preflight; bump runner to 2.338.0 #64) passed right before the hanging call, so this is not RBAC and not a fully-down API server.The important detail is that retrying alone is not enough: a conntrack entry keeps the DNAT mapping for the life of the connection, so a retry only helps if the previous attempt is abandoned and a new connection is opened. That requires a per-request timeout.
Changes
prunePods()/pruneSecrets()now run everylistanddeletecall throughretryK8sApiCall. Cleanup uses a larger budget than the default: 6 attempts, 15s per-request timeout, 3/6/12/15/15s backoff (~141s worst case), sized to ride through the ~127s kernel SYN-retry window.createJobPod()/createContainerStepPod()/createDockerSecret()/createSecretForEnvs()use the same policy. They run on the same ClusterIP path, and 3 of the 10ETIMEDOUTevents in the linked analysis happened increateJobPodduring Prepare — before this change those were uncovered.409 AlreadyExists. That is treated as success by reading the object back (readNamespacedPod/readNamespacedSecret), instead of failing the job.NotFound. Failing the job on that 404 would recreate the exact symptom this PR removes.code=ETIMEDOUT) instead of logging[object Object]for plain-object errors.CoreV1Apiclient and retry options so the logic is unit-testable without a cluster. Existing call sites (prepare-job,cleanup-job) are unchanged.deleteNamespacedPodkeepsgracePeriodSeconds: 0, matching the previousdeletePod()behavior;deleteNamespacedSecretkeeps the previous parameters.deleteSecret()was left behind by the inlining above and had no remaining callers, so it is removed.Tests
npm install --prefix packages/hooklib && npm run build --prefix packages/hooklib npm install --prefix packages/k8s npx tsc --noEmit -p packages/k8s npx jest --config packages/k8s/jest.config.js tests/prune-retry-test.ts tests/retry-utils-test.ts --runInBand npx eslint packages/k8s/src/k8s/index.ts packages/k8s/tests/prune-retry-test.tspackages/k8s/tests/prune-retry-test.tscovers 22 cases: transient list/delete/create retries, a hung request abandoned after the per-request timeout and retried, a 404 treated as already-deleted, a 404 arriving after a dropped connection still treated as success, a 409 on a retried create read back as success (including a read-back that has to be retried itself), a non-retryable and a non-AlreadyExists error still failing, and secrets list/delete/create retry.Scope note
This PR only adds timeout + retry and the idempotency that comes with it. One thing is intentionally not covered: making cleanup best-effort (warn and exit 0). Changing the job's failure semantics is a policy decision and should be a separate PR — with the current budget a dead path can still fail the job after ~141s instead of today's ~127s kernel timeout.
Related
Resolve https://github.com/opensourceways/ascend-ci-deployment/issues/2656 — root cause analysis and cluster-side evidence (HK-001 CI
Stop containerstimeouts, same incident as #2638).