Skip to content

Commit

Permalink
internal/lsp/cache: treat load timeouts as critical errors
Browse files Browse the repository at this point in the history
Lower the timeout for the go command to 10 minutes.
Also, if the first workspace load attempt fails because it times out,
treat the timeout as a critical error, since we explicitly don't cancel
the first workspace load.

Fixes golang/go#46859

Change-Id: Iccd26509177e4c47ca4b2c8ab4111df9be0f934e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/330969
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: Robert Findley <rfindley@google.com>
  • Loading branch information
stamblerre committed Jun 29, 2021
1 parent 12f8456 commit 100b229
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/lsp/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
// 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)
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()

cfg := s.config(ctx, inv)
Expand Down
11 changes: 9 additions & 2 deletions internal/lsp/cache/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,19 @@ func (s *snapshot) loadWorkspace(ctx context.Context, firstAttempt bool) {
if len(scopes) > 0 {
err = s.load(ctx, firstAttempt, append(scopes, packagePath("builtin"))...)
}
if ctx.Err() != nil {
// If the context is canceled on the first attempt, loading has failed
// because the go command has timed out--that should be a critical error.
if !firstAttempt && ctx.Err() != nil {
return
}

var criticalErr *source.CriticalError
if err != nil {
if ctx.Err() != nil {
event.Error(ctx, fmt.Sprintf("initial workspace load: %v", err), err)
criticalErr = &source.CriticalError{
MainError: err,
}
} else if err != nil {
event.Error(ctx, "initial workspace load failed", err)
extractedDiags, _ := s.extractGoCommandErrors(ctx, err.Error())
criticalErr = &source.CriticalError{
Expand Down

0 comments on commit 100b229

Please sign in to comment.