diff --git a/internal/job/executor.go b/internal/job/executor.go index b531448519..ba48243465 100644 --- a/internal/job/executor.go +++ b/internal/job/executor.go @@ -1268,13 +1268,17 @@ func (e *Executor) kubernetesSetup(ctx context.Context, k8sAgentSocket *kubernet go func() { // If the k8s client is interrupted because the "server" agent is // stopped or unreachable, we should stop running the job. - // If the k8s client is interrupted because our own ctx was cancelled, - // then the job is already stopping, so there's no point logging an - // error. - if err := k8sAgentSocket.Await(ctx, kubernetes.RunStateInterrupt); err != nil && !errors.Is(err, context.Canceled) { - e.shell.Errorf("Error waiting for client interrupt: %v", err) + err := k8sAgentSocket.Await(ctx, kubernetes.RunStateInterrupt) + if err != nil { + // If the k8s client is interrupted because our own ctx was cancelled, + // then the job is already stopping, so there's no point logging an + // error. + if !errors.Is(err, context.Canceled) { + e.shell.Errorf("Error waiting for client interrupt: %v", err) + } + // If there's an error from Await, we should Cancel the job. + e.Cancel() } - e.Cancel() }() return nil }