internal/lsp: fix race condition caused by config in `go mod tidy`

Reusing the config causes a race condition because it may be modified.
Get a new config in the bound function instead.
See the logs here:
https://storage.googleapis.com/go-build-log/23cc16cd/linux-amd64-race_343e911a.log.

Change-Id: Iaab43631740e43ba97cd70f7cd8a3bbaa91c26c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257206
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>
This commit is contained in:
Rebecca Stambler 2020-09-24 18:22:41 -04:00
parent 34b80a0a46
commit 4c77dbd9e5
1 changed files with 3 additions and 0 deletions

View File

@ -106,6 +106,9 @@ func (s *snapshot) ModTidy(ctx context.Context, fh source.FileHandle) (*source.T
err: err,
}
}
// Get a new config to avoid races, since it may be modified by
// goCommandInvocation.
cfg := s.configWithDir(ctx, filepath.Dir(fh.URI().Filename()))
tmpURI, runner, inv, cleanup, err := snapshot.goCommandInvocation(ctx, cfg, true, "mod", []string{"tidy"})
if err != nil {
return &modTidyData{err: err}