Skip to content

Commit

Permalink
Merge pull request #2935 from buildkite/fix/spurious-cancellations
Browse files Browse the repository at this point in the history
Prevent Cancel from running when a k8s job is cancelled already
  • Loading branch information
CerealBoy authored Aug 19, 2024
2 parents 08f161e + 2642551 commit 266d119
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,14 @@ 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.
err := k8sAgentSocket.Await(ctx, kubernetes.RunStateInterrupt)
// 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) {
if errors.Is(err, context.Canceled) {
return
}
if err != nil {
e.shell.Errorf("Error waiting for client interrupt: %v", err)
}
e.Cancel()
Expand Down

0 comments on commit 266d119

Please sign in to comment.