fix(k8s): replace blocking time.sleep with asyncio.sleep in _wait_for_sandbox_ready #841
Merged
Pangjiping merged 1 commit intoalibaba:mainfrom May 7, 2026
Conversation
…_sandbox_ready When the workload is not yet visible after creation, the polling loop fell into a time.sleep branch instead of await asyncio.sleep. This blocked the event loop during sandbox creation, preventing FastAPI from handling other requests (including /health), which could cause liveness probe failures and pod restarts. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an event-loop blocking bug in the Kubernetes sandbox readiness polling loop by replacing a synchronous sleep call with an async sleep inside the _wait_for_sandbox_ready coroutine. This prevents FastAPI/ASGI request handling (e.g., /health) from being stalled while waiting for the workload to appear in the Kubernetes API.
Changes:
- Replace
time.sleep(...)withawait asyncio.sleep(...)when the workload is not yet visible during polling. - Keep polling behavior consistent across both sleep branches in the loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Thanks for merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
_wait_for_sandbox_ready, the polling loop has twosleepbranches with inconsistent behavior:When a workload is not yet visible in the K8s API immediately after creation, the code falls into the
time.sleepbranch. Since_wait_for_sandbox_readyis anasyncmethod, this blocks the entire event loop forpoll_interval_seconds(default: 1s) per iteration.Impact
/healthFix
Replace
time.sleepwithawait asyncio.sleepin thenot workloadbranch, consistent with the sleep call later in the same loop.File:
server/opensandbox_server/services/k8s/kubernetes_service.py:199