From 65a71e5df3ed6969fec8c13659108ab4c1d909c4 Mon Sep 17 00:00:00 2001 From: EinoPlasma <30439029+EinoPlasma@users.noreply.github.com> Date: Sat, 18 Jan 2025 21:09:36 +0800 Subject: [PATCH] refactor: signal handling to improve clarity and correctness (#1980) --- signals.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/signals.go b/signals.go index 6f908472..010faeaf 100644 --- a/signals.go +++ b/signals.go @@ -8,20 +8,20 @@ import ( "github.com/go-task/task/v3/internal/logger" ) -const interruptSignalsCount = 3 +const maxInterruptSignals = 3 // NOTE(@andreynering): This function intercepts SIGINT and SIGTERM signals // so the Task process is not killed immediately and processes running have // time to do cleanup work. func (e *Executor) InterceptInterruptSignals() { - ch := make(chan os.Signal, interruptSignalsCount) + ch := make(chan os.Signal, maxInterruptSignals) signal.Notify(ch, os.Interrupt, syscall.SIGTERM) go func() { - for i := range interruptSignalsCount { + for i := 0; i < maxInterruptSignals; i++ { sig := <-ch - if i+1 >= interruptSignalsCount { + if i+1 >= maxInterruptSignals { e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig) os.Exit(1) }