Skip to content

Commit

Permalink
feat: disable timeout if timeout <= 0 (#5250)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Dec 25, 2024
1 parent 0b08f09 commit 286701c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/flagsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
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)"))

Expand Down
15 changes: 11 additions & 4 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,21 @@ 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
if needTrackResources { // wait until resource tracking finished to print properly

// Note: this defer must be before ctx.cancel defer
defer func() {
// wait until resource tracking finished to print properly
if needTrackResources {
<-trackResourcesEndCh
}
}()

ctx, cancel := context.WithTimeout(context.Background(), c.cfg.Run.Timeout)
defer cancel()
ctx := context.Background()
if c.cfg.Run.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, c.cfg.Run.Timeout)
defer cancel()
}

if needTrackResources {
go watchResources(ctx, trackResourcesEndCh, c.log, c.debugf)
Expand Down

0 comments on commit 286701c

Please sign in to comment.