Skip to content

Commit 1e644bb

Browse files
author
roberttwang
committed
Fail a Docker sandbox that never becomes ready
1 parent 62dd267 commit 1e644bb

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎internal/runtime/runtime_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ func TestIsSandboxInterrupt(t *testing.T) {
242242
if !IsSandboxInterrupt(wrapped) {
243243
t.Fatalf("annotated exec-gone should interrupt, got %v", wrapped)
244244
}
245+
startup := &ConversationWorkspaceSetupError{Cause: fmt.Errorf("%w: %w", errDockerWorkspaceNotReady, wrapped)}
246+
if IsSandboxInterrupt(startup) {
247+
t.Fatalf("sandbox that never starts must fail without requeuing: %v", startup)
248+
}
245249
}
246250

247251
func TestAnnotateDockerExecErrorKeepsDaemonLine(t *testing.T) {

‎internal/runtime/sandbox_docker.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ const (
9292
legacyDockerScriptSuffix = "-scripts"
9393
)
9494

95+
var errDockerWorkspaceNotReady = errors.New("docker workspace not ready")
96+
9597
func removeDockerWorkspaceContainers(ctx context.Context, container string) error {
9698
// Older runs can still own a script companion. Reclaim it with the workspace.
9799
if err := removeDockerContainer(ctx, container+legacyDockerScriptSuffix); err != nil {
@@ -404,6 +406,11 @@ func IsSandboxInterrupt(err error) bool {
404406
if errors.Is(err, context.Canceled) {
405407
return true
406408
}
409+
// An image that never starts may report the same daemon message as a
410+
// running sandbox that disappeared. Only the latter can be resumed.
411+
if errors.Is(err, errDockerWorkspaceNotReady) {
412+
return false
413+
}
407414
msg := strings.ToLower(err.Error())
408415
return strings.Contains(msg, "context canceled") ||
409416
strings.Contains(msg, "signal: killed") ||
@@ -1034,7 +1041,7 @@ func waitDockerWorkspaceReady(ctx context.Context, name string) error {
10341041
if lastErr == nil {
10351042
lastErr = fmt.Errorf("unexpected pwd output %q", strings.TrimSpace(string(lastOut)))
10361043
}
1037-
return fmt.Errorf("docker workspace not ready: %w: %s", lastErr, strings.TrimSpace(string(lastOut)))
1044+
return fmt.Errorf("%w: %w: %s", errDockerWorkspaceNotReady, lastErr, strings.TrimSpace(string(lastOut)))
10381045
}
10391046
time.Sleep(200 * time.Millisecond)
10401047
}

0 commit comments

Comments
 (0)