diff --git a/cli/cliui/agent.go b/cli/cliui/agent.go index 5d827bc1ec2a7..a6993954dfd9b 100644 --- a/cli/cliui/agent.go +++ b/cli/cliui/agent.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "io" + "os" + "os/signal" "sync" "time" @@ -46,6 +48,23 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error { spin.Start() defer spin.Stop() + ctx, cancelFunc := context.WithCancel(ctx) + defer cancelFunc() + stopSpin := make(chan os.Signal, 1) + signal.Notify(stopSpin, os.Interrupt) + defer signal.Stop(stopSpin) + go func() { + select { + case <-ctx.Done(): + return + case <-stopSpin: + } + signal.Stop(stopSpin) + spin.Stop() + // nolint:revive + os.Exit(1) + }() + ticker := time.NewTicker(opts.FetchInterval) defer ticker.Stop() timer := time.NewTimer(opts.WarnInterval) diff --git a/provisionerd/provisionerd.go b/provisionerd/provisionerd.go index 286643624493c..c06a3365da55c 100644 --- a/provisionerd/provisionerd.go +++ b/provisionerd/provisionerd.go @@ -845,7 +845,7 @@ func (p *Server) failActiveJob(failedJob *proto.FailedJob) { return } if p.jobFailed.Load() { - p.opts.Logger.Warn(context.Background(), "job has already been marked as failed", slog.F("error_messsage", failedJob.Error)) + p.opts.Logger.Debug(context.Background(), "job has already been marked as failed", slog.F("error_messsage", failedJob.Error)) return } p.jobFailed.Store(true)