From 7ad3e53899e9f8f3a56298e7f739ac5309987394 Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Fri, 7 Jun 2024 16:53:37 +0200 Subject: [PATCH] fix: change so that second SIGINT signal immediately exits program (#2598) ## Description This changes the behavior so that the second SIGINT signal immediately exits. This is useful if a process is not quitting in context cancel or if it is taking too long to quit. ## Related Issue Relates to #2594 ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow) followed --- main.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 0449ccd119..8068f4b4fc 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ package main import ( "context" "embed" + "os" "os/signal" "syscall" @@ -22,8 +23,22 @@ var cosignPublicKey string var zarfSchema embed.FS func main() { - ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() + signalCh := make(chan os.Signal, 1) + signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM) + go func() { + first := true + for { + <-signalCh + if first { + first = false + cancel() + continue + } + os.Exit(1) + } + }() config.CosignPublicKey = cosignPublicKey lint.ZarfSchema = zarfSchema