From b198df8e31c9b48b45cd57f4d284552dab4eeb85 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 22 Dec 2024 02:22:14 +0100 Subject: [PATCH 1/6] feat: disable timeout if timeout <= 0 --- pkg/commands/run.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index ff7c5e467b67..210fb1e39ab3 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -244,8 +244,14 @@ func (c *runCommand) execute(_ *cobra.Command, args []string) { } }() - ctx, cancel := context.WithTimeout(context.Background(), c.cfg.Run.Timeout) - defer cancel() + var ctx context.Context + if c.cfg.Run.Timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(context.Background(), c.cfg.Run.Timeout) + defer cancel() + } else { + ctx = context.Background() + } if needTrackResources { go watchResources(ctx, trackResourcesEndCh, c.log, c.debugf) From 0a32d9f786b8a2739778a002225106e865a3133c Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 25 Dec 2024 01:54:00 +0100 Subject: [PATCH 2/6] review --- pkg/commands/run.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 210fb1e39ab3..5947c92357ad 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -238,19 +238,17 @@ func (c *runCommand) execute(_ *cobra.Command, args []string) { needTrackResources := logutils.IsVerbose() || c.opts.PrintResourcesUsage trackResourcesEndCh := make(chan struct{}) - defer func() { // XXX: this defer must be before ctx.cancel defer + defer func() { // XXX: this defer must be before ctx.cancel defer if needTrackResources { // wait until resource tracking finished to print properly <-trackResourcesEndCh } }() - var ctx context.Context + ctx := context.Background() if c.cfg.Run.Timeout > 0 { var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(context.Background(), c.cfg.Run.Timeout) + ctx, cancel = context.WithTimeout(ctx, c.cfg.Run.Timeout) defer cancel() - } else { - ctx = context.Background() } if needTrackResources { From 1b567b0cc785d504c11ec8581008271d5eefebaf Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 25 Dec 2024 01:56:04 +0100 Subject: [PATCH 3/6] chore: clean comment --- pkg/commands/run.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 5947c92357ad..cd9b7a390eb5 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -238,7 +238,9 @@ func (c *runCommand) execute(_ *cobra.Command, args []string) { needTrackResources := logutils.IsVerbose() || c.opts.PrintResourcesUsage trackResourcesEndCh := make(chan struct{}) - defer func() { // XXX: this defer must be before ctx.cancel defer + + // Note: this defer must be before ctx.cancel defer + defer func() { if needTrackResources { // wait until resource tracking finished to print properly <-trackResourcesEndCh } From 5967a2e68ce9477e185507b4e88f75698c2549ef Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 25 Dec 2024 02:34:50 +0100 Subject: [PATCH 4/6] chore: clean comment --- pkg/commands/run.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index cd9b7a390eb5..d9aa7578cd70 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -241,7 +241,8 @@ func (c *runCommand) execute(_ *cobra.Command, args []string) { // Note: this defer must be before ctx.cancel defer defer func() { - if needTrackResources { // wait until resource tracking finished to print properly + // wait until resource tracking finished to print properly + if needTrackResources { <-trackResourcesEndCh } }() From 63d867468aaec5dfbdc38bbdd9b84ff6222c5add Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 25 Dec 2024 12:17:01 +0100 Subject: [PATCH 5/6] review --- .golangci.next.reference.yml | 1 + pkg/commands/flagsets.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 747177ba5b2b..83ed0728f545 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4091,6 +4091,7 @@ output: # Options for analysis running. run: # Timeout for analysis, e.g. 30s, 5m. + # If the value is lower or equal to 0, the timeout is disabled. # Default: 1m timeout: 5m diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 608f6b9de581..e934325ec44e 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -49,7 +49,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { internal.AddFlagAndBind(v, fs, fs.String, "go", "run.go", "", color.GreenString("Targeted Go version")) internal.AddHackedStringSlice(fs, "build-tags", color.GreenString("Build tags")) - internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, color.GreenString("Timeout for total work")) + internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, color.GreenString("Timeout for total work. If <= 0, the timeout is disabled")) internal.AddFlagAndBind(v, fs, fs.Bool, "tests", "run.tests", true, color.GreenString("Analyze tests (*_test.go)")) From 4b28f5fc404badadb9cdc69e8a46bd60262b8dfd Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 25 Dec 2024 12:41:12 +0100 Subject: [PATCH 6/6] lll you will never be my friend --- pkg/commands/flagsets.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index e934325ec44e..5e7944acf08d 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -49,7 +49,8 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { internal.AddFlagAndBind(v, fs, fs.String, "go", "run.go", "", color.GreenString("Targeted Go version")) internal.AddHackedStringSlice(fs, "build-tags", color.GreenString("Build tags")) - internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, color.GreenString("Timeout for total work. If <= 0, the timeout is disabled")) + internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, + color.GreenString("Timeout for total work. If <= 0, the timeout is disabled")) internal.AddFlagAndBind(v, fs, fs.Bool, "tests", "run.tests", true, color.GreenString("Analyze tests (*_test.go)"))