fix deadline handling
This commit is contained in:
parent
9d95267977
commit
100efea259
@ -47,14 +47,6 @@ func runLinters(ctx context.Context, wg *sync.WaitGroup, tasksCh chan Linter, li
|
|||||||
go func(i int) {
|
go func(i int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for {
|
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 {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
@ -62,6 +54,11 @@ func runLinters(ctx context.Context, wg *sync.WaitGroup, tasksCh chan Linter, li
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
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)
|
res, lerr := runLinter(ctx, linter, lintCtx, i)
|
||||||
lintResultsCh <- lintRes{
|
lintResultsCh <- lintRes{
|
||||||
linter: linter,
|
linter: linter,
|
||||||
@ -84,7 +81,7 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
|
|||||||
os.Stdout, os.Stderr = devNull, devNull
|
os.Stdout, os.Stderr = devNull, devNull
|
||||||
|
|
||||||
lintResultsCh := make(chan lintRes, len(linters))
|
lintResultsCh := make(chan lintRes, len(linters))
|
||||||
tasksCh := make(chan Linter, lintCtx.Cfg.Common.Concurrency)
|
tasksCh := make(chan Linter, len(linters))
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(lintCtx.Cfg.Common.Concurrency)
|
wg.Add(lintCtx.Cfg.Common.Concurrency)
|
||||||
runLinters(ctx, &wg, tasksCh, lintResultsCh, lintCtx)
|
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
|
os.Stdout, os.Stderr = savedStdout, savedStderr
|
||||||
results := []result.Result{}
|
results := []result.Result{}
|
||||||
|
finishedN := 0
|
||||||
for res := range lintResultsCh {
|
for res := range lintResultsCh {
|
||||||
if res.err != nil {
|
if res.err != nil {
|
||||||
analytics.Log(ctx).Warnf("Can't run linter %s: %s", res.linter.Name(), res.err)
|
analytics.Log(ctx).Warnf("Can't run linter %s: %s", res.linter.Name(), res.err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finishedN++
|
||||||
if res.res == nil || len(res.res.Issues) == 0 {
|
if res.res == nil || len(res.res.Issues) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -112,6 +111,11 @@ func (r SimpleRunner) Run(ctx context.Context, linters []Linter, lintCtx *golint
|
|||||||
results = append(results, *res.res)
|
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)
|
results, err = r.processResults(ctx, results)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't process results: %s", err)
|
return nil, fmt.Errorf("can't process results: %s", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user