Skip to content

Commit 8860a70

Browse files
committed
internal/lsp/cache: set a 15 minute deadline on calls to packages.Load
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 <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 51cde52 commit 8860a70

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/lsp/cache/load.go

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path/filepath"
1414
"sort"
1515
"strings"
16+
"time"
1617

1718
"golang.org/x/tools/go/packages"
1819
"golang.org/x/tools/internal/event"
@@ -98,6 +99,13 @@ func (s *snapshot) load(ctx context.Context, scopes ...interface{}) error {
9899
if err != nil {
99100
return err
100101
}
102+
103+
// Set a last resort deadline on packages.Load since it calls the go
104+
// command, which may hang indefinitely if it has a bug. golang/go#42132
105+
// and golang/go#42255 have more context.
106+
ctx, cancel := context.WithTimeout(ctx, 15*time.Minute)
107+
defer cancel()
108+
101109
cfg := s.config(ctx, inv)
102110
pkgs, err := packages.Load(cfg, query...)
103111
cleanup()

0 commit comments

Comments
 (0)