Skip to content

Commit

Permalink
gopls/internal/lsp/cache: in tests, show all stacks during analyzer c…
Browse files Browse the repository at this point in the history
…rash

We recently started using bug.Errorf to report analyzer crashes,
causing tests to fail sporadically. Unfortunately the log included
only the "panicked" message but not the relevant stack of the panic
or of the other goroutines, giving limited evidence on which to
investigate the underlying cause, suspected to be in package loading,
not the analyzer itself.

This change causes such crashes to display all stacks so that we
can gather more evidence over the next few days before we suppress
the crashes again.

Updates golang/go#54762
Updates golang/go#56035

Change-Id: I2d29e05b5910540918816e695b458463a05f94d9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439116
Reviewed-by: Bryan Mills <[email protected]>
Run-TryBot: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
gopls-CI: kokoro <[email protected]>
  • Loading branch information
adonovan committed Oct 5, 2022
1 parent dc88e7b commit 2d32e15
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions gopls/internal/lsp/cache/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,20 @@ func actionImpl(ctx context.Context, snapshot *snapshot, deps []*actionHandle, a
var result interface{}
var err error
func() {
// Set this flag temporarily when debugging crashes.
// See https://github.com/golang/go/issues/54762.
const norecover = false
if norecover {
debug.SetTraceback("all") // show all goroutines
} else {
defer func() {
if r := recover(); r != nil {
// Use bug.Errorf so that we detect panics during testing.
err = bug.Errorf("analysis %s for package %s panicked: %v", analyzer.Name, pkg.PkgPath(), r)
defer func() {
if r := recover(); r != nil {
// An Analyzer crashed. This is often merely a symptom
// of a problem in package loading.
if bug.PanicOnBugs {
// During testing, crash. See issues 54762, 56035.
debug.SetTraceback("all") // show all goroutines
panic(r)
} else {
// In production, suppress the panic and press on.
err = fmt.Errorf("analysis %s for package %s panicked: %v", analyzer.Name, pkg.PkgPath(), r)
}
}()
}
}
}()
result, err = pass.Analyzer.Run(pass)
}()
if err != nil {
Expand Down

0 comments on commit 2d32e15

Please sign in to comment.