Skip to content

Commit 286701c

Browse files
authored
feat: disable timeout if timeout <= 0 (#5250)
1 parent 0b08f09 commit 286701c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.golangci.next.reference.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4091,6 +4091,7 @@ output:
40914091
# Options for analysis running.
40924092
run:
40934093
# Timeout for analysis, e.g. 30s, 5m.
4094+
# If the value is lower or equal to 0, the timeout is disabled.
40944095
# Default: 1m
40954096
timeout: 5m
40964097

pkg/commands/flagsets.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
4949
internal.AddFlagAndBind(v, fs, fs.String, "go", "run.go", "", color.GreenString("Targeted Go version"))
5050
internal.AddHackedStringSlice(fs, "build-tags", color.GreenString("Build tags"))
5151

52-
internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout, color.GreenString("Timeout for total work"))
52+
internal.AddFlagAndBind(v, fs, fs.Duration, "timeout", "run.timeout", defaultTimeout,
53+
color.GreenString("Timeout for total work. If <= 0, the timeout is disabled"))
5354

5455
internal.AddFlagAndBind(v, fs, fs.Bool, "tests", "run.tests", true, color.GreenString("Analyze tests (*_test.go)"))
5556

pkg/commands/run.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,21 @@ func (c *runCommand) execute(_ *cobra.Command, args []string) {
238238
needTrackResources := logutils.IsVerbose() || c.opts.PrintResourcesUsage
239239

240240
trackResourcesEndCh := make(chan struct{})
241-
defer func() { // XXX: this defer must be before ctx.cancel defer
242-
if needTrackResources { // wait until resource tracking finished to print properly
241+
242+
// Note: this defer must be before ctx.cancel defer
243+
defer func() {
244+
// wait until resource tracking finished to print properly
245+
if needTrackResources {
243246
<-trackResourcesEndCh
244247
}
245248
}()
246249

247-
ctx, cancel := context.WithTimeout(context.Background(), c.cfg.Run.Timeout)
248-
defer cancel()
250+
ctx := context.Background()
251+
if c.cfg.Run.Timeout > 0 {
252+
var cancel context.CancelFunc
253+
ctx, cancel = context.WithTimeout(ctx, c.cfg.Run.Timeout)
254+
defer cancel()
255+
}
249256

250257
if needTrackResources {
251258
go watchResources(ctx, trackResourcesEndCh, c.log, c.debugf)

0 commit comments

Comments
 (0)