From 08e7ed36a3141b3e6055a53d5b35056fbcb01ed0 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 29 Jan 2026 19:38:03 +0800 Subject: [PATCH] Implement Container Readiness Check in Manager - Added a loop in the ensureRunning method to wait for the Docker container to be in a running state before proceeding, enhancing reliability in container management. - Included error handling for container inspection to ensure proper feedback in case of failures during the readiness check. --- sandbox/manager.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sandbox/manager.go b/sandbox/manager.go index 9052ff28..7249da95 100644 --- a/sandbox/manager.go +++ b/sandbox/manager.go @@ -231,6 +231,18 @@ func (m *Manager) ensureRunning(ctx context.Context, name string) error { return fmt.Errorf("failed to start container: %w", err) } + // Wait for container to be ready (inspect until running) + for i := 0; i < 30; i++ { + info, err := m.dockerClient.ContainerInspect(ctx, cont.ID) + if err != nil { + return fmt.Errorf("failed to inspect container: %w", err) + } + if info.State.Running { + break + } + time.Sleep(100 * time.Millisecond) + } + m.mu.Lock() cont.Status = StatusRunning cont.LastUsedAt = time.Now()