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>
diff --git a/internal/lsp/cache/mod_tidy.go b/internal/lsp/cache/mod_tidy.go
index 646a90f..462be86 100644
--- a/internal/lsp/cache/mod_tidy.go
+++ b/internal/lsp/cache/mod_tidy.go
@@ -106,6 +106,9 @@
 				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}