Skip to content

feat: disable timeout if timeout <= 0 #5250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading