Repository navigation
fix(server): stop waiting for a Kubernetes sandbox deleted during creation - #3118
Pangjiping merged 2 commits into
Conversation
…ation The create wait loop treated Stopping (deletionTimestamp set) as a non-terminal state and kept polling a workload that had disappeared, so a sandbox deleted while its create request was waiting held that request until POD_READY_TIMEOUT and then answered 504 "Timeout waiting ... Last state: Stopping". Fail with 409, as for a sandbox that reaches Terminated first, when the workload is Stopping or vanishes after it was seen. Signed-off-by: kongxin <kongxin326@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d6d965136
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if last_workload is not None: | ||
| # It existed and is gone: deleted while we waited. | ||
| raise _deleted_before_ready_error(sandbox_id) |
There was a problem hiding this comment.
Seed deletion detection from the successful create
When DELETE or TTL removal completes after create_workload returns but before _wait_for_sandbox_ready completes its first successful GET (the caller also attaches PVC owner references before invoking this method), last_workload is still None, so this branch treats every subsequent 404 as “not found yet” and still waits until returning the timeout 504. Pass or seed the already-returned workload_info/known-created state so this immediate-deletion race receives the intended 409 as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, this was real. If the DELETE or TTL removal landed between create_workload returning and the first GET, last_workload stayed None, so every 404 counted as "not visible yet" and the request still ran to the 504 (Last state: None).
Fixed in f4e6e6d: _wait_for_sandbox_ready now takes workload_created, and create_sandbox passes True, so the first 404 after a successful create fails with the same 409. This is safe because a cache miss in get_custom_object falls through to a live API GET, so that 404 comes from the API server and not from informer lag. The flag defaults to False, so other callers still poll until the workload first appears.
Test: test_create_sandbox_fails_fast_when_deleted_before_first_read drives create_sandbox with every GET returning 404 and expects a 409 after one read. Before the fix it failed with 504 == 409. There is also a unit test on the wait itself. The full server suite passes (3199 passed, 34 skipped).
…wait The wait loop only reported "deleted before it was ready" once a GET had returned the workload. A DELETE or TTL removal that landed between create_workload returning and the first GET left every read a 404, which the loop took as "not visible yet" and polled until POD_READY_TIMEOUT (504, Last state: None). create_sandbox now tells the wait that the workload already exists, so the first 404 fails with the same 409. A cache miss falls through to a live API GET, so that 404 is authoritative rather than informer lag. Signed-off-by: kongxin <kongxin326@gmail.com>
Summary
_wait_for_sandbox_readyfails fast on Running, Failed, Terminated, quota and unschedulable, but not on deletion. A BatchSandbox that is being deleted reportsStopping(deletionTimestamp set), and once it is goneget_workloadreturns nothing, which the loop treats as "not created yet". A sandbox deleted (by the user, or by TTL) while itsPOST /sandboxeswas still waiting kept that request open untilPOD_READY_TIMEOUTand then answered504 KUBERNETES::POD_READY_TIMEOUT("Timeout waiting ... Last state: Stopping").409it uses for a sandbox that reachesTerminatedbefore it is ready, when the workload isStoppingor disappears after it was seen. A workload that has not appeared yet is still polled as before.On a kind cluster (BatchSandbox provider, image that cannot be pulled so the sandbox stays Pending,
DELETE1 s after the create):504 KUBERNETES::POD_READY_TIMEOUT...Last state: Stopping409"Sandbox ... was deleted before it was ready (Sandbox is being deleted)"Testing
Not run (explain why)
Unit tests
Integration tests
e2e / manual verification
tests/k8s/test_kubernetes_service.py:test_wait_stops_when_sandbox_is_being_deletedandtest_wait_stops_when_seen_workload_disappearsfail onmain(the loop runs to its timeout) and pass with the change;test_wait_keeps_polling_until_workload_first_appearspins the unchanged behaviour for a workload that is not created yet.uv run pytest: 3197 passed, 34 skipped.uv run ruff check: clean.pyrightonkubernetes_service.py: same 6 pre-existing errors asmain.Manual: kind v1.37 cluster, controller from
kubernetes/cmd/controller, server with the BatchSandbox provider; numbers in the table above.Breaking Changes
A create whose sandbox is deleted while it waits now returns
409immediately instead of504after the ready timeout.Checklist