Skip to content

Commit 100efea

Browse files
committed
fix deadline handling
1 parent 9d95267 commit 100efea

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pkg/runner.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,18 @@ func runLinters(ctx context.Context, wg *sync.WaitGroup, tasksCh chan Linter, li
4747
go func(i int) {
4848
defer wg.Done()
4949
for {
50-
select {
51-
case <-ctx.Done():
52-
// XXX: if check it in a select with reading from tasksCh
53-
// it's possible to not enter to this case until tasksCh is empty.
54-
return
55-
default:
56-
}
57-
5850
select {
5951
case <-ctx.Done():
6052
return
6153
case linter, ok := <-tasksCh:
6254
if !ok {
6355
return
6456
}
57+
if ctx.Err() != nil {
58+
// XXX: if check it in only int a select
59+
// it's possible to not enter to this case until tasksCh is empty.
60+
return
61+
}
6562
res, lerr := runLinter(ctx, linter, lintCtx, i)
6663
lintResultsCh <- lintRes{
6764
linter: linter,
@@ -84,7 +81,7 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
8481
os.Stdout, os.Stderr = devNull, devNull
8582

8683
lintResultsCh := make(chan lintRes, len(linters))
87-
tasksCh := make(chan Linter, lintCtx.Cfg.Common.Concurrency)
84+
tasksCh := make(chan Linter, len(linters))
8885
var wg sync.WaitGroup
8986
wg.Add(lintCtx.Cfg.Common.Concurrency)
9087
runLinters(ctx, &wg, tasksCh, lintResultsCh, lintCtx)
@@ -99,19 +96,26 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
9996

10097
os.Stdout, os.Stderr = savedStdout, savedStderr
10198
results := []result.Result{}
99+
finishedN := 0
102100
for res := range lintResultsCh {
103101
if res.err != nil {
104102
analytics.Log(ctx).Warnf("Can't run linter %s: %s", res.linter.Name(), res.err)
105103
continue
106104
}
107105

106+
finishedN++
108107
if res.res == nil || len(res.res.Issues) == 0 {
109108
continue
110109
}
111110

112111
results = append(results, *res.res)
113112
}
114113

114+
if ctx.Err() != nil {
115+
analytics.Log(ctx).Warnf("%d/%d linters finished: deadline exceeded: try increase it by passing --deadline option",
116+
finishedN, len(linters))
117+
}
118+
115119
results, err = r.processResults(ctx, results)
116120
if err != nil {
117121
return nil, fmt.Errorf("can't process results: %s", err)

0 commit comments

Comments
 (0)