Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 91ac29a

Browse files
committed
don't crash in goroutines
1 parent e32c541 commit 91ac29a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lint/lint.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ import (
99
"io"
1010
"os"
1111
"path/filepath"
12+
"runtime/debug"
1213
"sort"
1314
"strings"
1415
"sync"
1516
"time"
1617
"unicode"
1718

18-
"golang.org/x/tools/go/packages"
1919
"github.com/golangci/go-tools/config"
2020
"github.com/golangci/go-tools/ssa"
2121
"github.com/golangci/go-tools/ssa/ssautil"
22+
"golang.org/x/tools/go/packages"
2223
)
2324

2425
type Job struct {
@@ -29,6 +30,7 @@ type Job struct {
2930
problems []Problem
3031

3132
duration time.Duration
33+
panicErr error
3234
}
3335

3436
type Ignore interface {
@@ -451,6 +453,11 @@ func (l *Linter) Lint(initial []*packages.Package, stats *PerfStats) []Problem {
451453
for _, j := range jobs {
452454
wg.Add(1)
453455
go func(j *Job) {
456+
defer func() {
457+
if panicErr := recover(); panicErr != nil {
458+
j.panicErr = fmt.Errorf("panic: %s: %s", panicErr, string(debug.Stack()))
459+
}
460+
}()
454461
defer wg.Done()
455462
sem <- struct{}{}
456463
defer func() { <-sem }()
@@ -466,6 +473,10 @@ func (l *Linter) Lint(initial []*packages.Package, stats *PerfStats) []Problem {
466473
wg.Wait()
467474

468475
for _, j := range jobs {
476+
if j.panicErr != nil {
477+
panic(j.panicErr)
478+
}
479+
469480
if stats != nil {
470481
stats.Jobs = append(stats.Jobs, JobStat{j.check.ID, j.duration})
471482
}

0 commit comments

Comments
 (0)