fix: Restore terminal on interrupt when connecting (#1312)

Fixes #1292.
This commit is contained in:
Kyle Carberry
2022-05-05 20:11:44 -05:00
committed by GitHub
parent f965066517
commit 914a2f477c
2 changed files with 20 additions and 1 deletions
+19
View File
@@ -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)
+1 -1
View File
@@ -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)