bug(trainer): wait_for_job_status() accepts zero or negative polling_interval causing CPU busy-loop or cryptic error
#550 opened on 2026年7月1日
Repository metrics
- Stars
- (124 stars)
- PR merge metrics
- (PR metrics pending)
説明
What happened?
TrainerClient.wait_for_job_status() accepts a polling_interval parameter but performs no validation on its value. When a user passes 0 or a negative number, one of two silent failure modes occurs:
-
polling_interval=0→time.sleep(0)is called in thewhile True:polling loop, causing a CPU busy-loop that hammers the Kubernetes API thousands of times per second with no visible error. -
polling_interval=-5→ Python raises a cryptic stdlib error (ValueError: sleep length must be non-negative) deep inside the call stack with no hint that the caller passed a bad value.
Neither case gives the user a helpful, actionable error message.
Method signature (from kubeflow/trainer/api/trainer_client.py):
def wait_for_job_status(
self,
name: str,
status: set[str] = {"Complete"},
timeout: int = 600,
polling_interval: int = 2, # ← no validation
callbacks: list[Callable[[TrainJob], None]] | None = None,
) -> TrainJob:
Steps to reproduce:
from kubeflow.trainer import TrainerClient
client = TrainerClient()
# Triggers CPU busy-loop:
client.wait_for_job_status("my-job", polling_interval=0)
# Triggers cryptic stdlib ValueError:
client.wait_for_job_status("my-job", polling_interval=-5)
Note: The same gap exists in ContainerBackend.wait_for_job_status() (tracked in #411). This issue covers the Kubernetes backend path in TrainerClient.
What did you expect to happen?
A clear, descriptive ValueError should be raised immediately when polling_interval <= 0, before any polling loop begins. Example:
ValueError: polling_interval must be a positive number, got: 0
This is consistent with how the SDK already documents ValueError in the wait_for_job_status() raises section ("The input values are incorrect") — the validation just needs to be implemented.
Environment
- Kubeflow SDK version: v0.4.0 (latest)
- Affected file:
kubeflow/trainer/api/trainer_client.py - Affected method:
TrainerClient.wait_for_job_status() - Related issue: #411 (same bug in
ContainerBackend) - Python: 3.9+
- Backend: KubernetesBackend (default)