fix deadline handling

This commit is contained in:
golangci 2018-05-07 16:38:05 +03:00
parent 9d95267977
commit 100efea259

View File

@ -47,14 +47,6 @@ func runLinters(ctx context.Context, wg *sync.WaitGroup, tasksCh chan Linter, li
go func(i int) {
defer wg.Done()
for {
select {
case <-ctx.Done():
// XXX: if check it in a select with reading from tasksCh
// it's possible to not enter to this case until tasksCh is empty.
return
default:
}
select {
case <-ctx.Done():
return
@ -62,6 +54,11 @@ func runLinters(ctx context.Context, wg *sync.WaitGroup, tasksCh chan Linter, li
if !ok {
return
}
if ctx.Err() != nil {
// XXX: if check it in only int a select
// it's possible to not enter to this case until tasksCh is empty.
return
}
res, lerr := runLinter(ctx, linter, lintCtx, i)
lintResultsCh <- lintRes{
linter: linter,
@ -84,7 +81,7 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
os.Stdout, os.Stderr = devNull, devNull
lintResultsCh := make(chan lintRes, len(linters))
tasksCh := make(chan Linter, lintCtx.Cfg.Common.Concurrency)
tasksCh := make(chan Linter, len(linters))
var wg sync.WaitGroup
wg.Add(lintCtx.Cfg.Common.Concurrency)
runLinters(ctx, &wg, tasksCh, lintResultsCh, lintCtx)
@ -99,12 +96,14 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
os.Stdout, os.Stderr = savedStdout, savedStderr
results := []result.Result{}
finishedN := 0
for res := range lintResultsCh {
if res.err != nil {
analytics.Log(ctx).Warnf("Can't run linter %s: %s", res.linter.Name(), res.err)
continue
}
finishedN++
if res.res == nil || len(res.res.Issues) == 0 {
continue
}
@ -112,6 +111,11 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
results = append(results, *res.res)
}
if ctx.Err() != nil {
analytics.Log(ctx).Warnf("%d/%d linters finished: deadline exceeded: try increase it by passing --deadline option",
finishedN, len(linters))
}
results, err = r.processResults(ctx, results)
if err != nil {
return nil, fmt.Errorf("can't process results: %s", err)