Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Restore terminal on interrupt when connecting
Fixes #1292.
  • Loading branch information
kylecarbs committed May 5, 2022
commit 22a709beb2bb66a889ce2d03d772bae3efe10ffe
19 changes: 19 additions & 0 deletions cli/cliui/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"os"
"os/signal"
"sync"
"time"

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down