Skip to content

Commit 914a2f4

Browse files
authored
fix: Restore terminal on interrupt when connecting (#1312)
Fixes #1292.
1 parent f965066 commit 914a2f4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cli/cliui/agent.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"os"
8+
"os/signal"
79
"sync"
810
"time"
911

@@ -46,6 +48,23 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
4648
spin.Start()
4749
defer spin.Stop()
4850

51+
ctx, cancelFunc := context.WithCancel(ctx)
52+
defer cancelFunc()
53+
stopSpin := make(chan os.Signal, 1)
54+
signal.Notify(stopSpin, os.Interrupt)
55+
defer signal.Stop(stopSpin)
56+
go func() {
57+
select {
58+
case <-ctx.Done():
59+
return
60+
case <-stopSpin:
61+
}
62+
signal.Stop(stopSpin)
63+
spin.Stop()
64+
// nolint:revive
65+
os.Exit(1)
66+
}()
67+
4968
ticker := time.NewTicker(opts.FetchInterval)
5069
defer ticker.Stop()
5170
timer := time.NewTimer(opts.WarnInterval)

provisionerd/provisionerd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ func (p *Server) failActiveJob(failedJob *proto.FailedJob) {
845845
return
846846
}
847847
if p.jobFailed.Load() {
848-
p.opts.Logger.Warn(context.Background(), "job has already been marked as failed", slog.F("error_messsage", failedJob.Error))
848+
p.opts.Logger.Debug(context.Background(), "job has already been marked as failed", slog.F("error_messsage", failedJob.Error))
849849
return
850850
}
851851
p.jobFailed.Store(true)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy