Skip to content

Commit

Permalink
internal/lsp/cache: set a 15 minute deadline on calls to packages.Load
Browse files Browse the repository at this point in the history
We've recently noticed multiple instances of `go list` hanging
indefinitely during an initial workspace load. Heschi suggested setting
a 5 minute deadline on the IWL, but it seems reasonable to set this
deadline on all calls to packages.Load since that calls `go list`.

I also started with a 15 minute deadline to be a little more careful.
Do you think this is risky enough to merit an experimental setting?

Fixes golang/go#42132

Change-Id: I0a38741f3d99b6a38c46c3e663daf61f2cb45581
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266478
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
  • Loading branch information
stamblerre committed Nov 2, 2020
1 parent 51cde52 commit 8860a70
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/lsp/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"sort"
"strings"
"time"

"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/event"
Expand Down Expand Up @@ -98,6 +99,13 @@ func (s *snapshot) load(ctx context.Context, scopes ...interface{}) error {
if err != nil {
return err
}

// Set a last resort deadline on packages.Load since it calls the go
// command, which may hang indefinitely if it has a bug. golang/go#42132
// and golang/go#42255 have more context.
ctx, cancel := context.WithTimeout(ctx, 15*time.Minute)
defer cancel()

cfg := s.config(ctx, inv)
pkgs, err := packages.Load(cfg, query...)
cleanup()
Expand Down

0 comments on commit 8860a70

Please sign in to comment.