diff options
author | Robert Findley <rfindley@google.com> | 2023-03-06 12:55:37 -0500 |
---|---|---|
committer | Robert Findley <rfindley@google.com> | 2023-03-06 18:12:21 +0000 |
commit | c91d0b88c3be5a2b7990992fb3c153277f26c5eb (patch) | |
tree | 2220716a9ea26a48a43bbeb858af0145bf326422 | |
parent | c0742f584bb22bf982da6377387cc647cafc0ffd (diff) | |
download | golang-x-tools-c91d0b88c3be5a2b7990992fb3c153277f26c5eb.tar.gz |
gopls/internal/lsp/source: guard against concurrent writes in xrefs
Add a missing mutex to guard map writes while expanding the references
search.
Change-Id: Ie02f5ba18ec3d78a802e2c373c9c6d18f45b883b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/473675
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
-rw-r--r-- | gopls/internal/lsp/source/references.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/gopls/internal/lsp/source/references.go b/gopls/internal/lsp/source/references.go index 8f0fbfc16..3f8960180 100644 --- a/gopls/internal/lsp/source/references.go +++ b/gopls/internal/lsp/source/references.go @@ -393,6 +393,7 @@ func expandMethodSearch(ctx context.Context, snapshot Snapshot, method *types.Fu if err != nil { return err } + var mu sync.Mutex // guards scope and targets var group errgroup.Group for i, index := range indexes { i := i @@ -400,16 +401,19 @@ func expandMethodSearch(ctx context.Context, snapshot Snapshot, method *types.Fu group.Go(func() error { // Consult index for matching methods. results := index.Search(key, method.Name()) + if len(results) == 0 { + return nil + } // Expand global search scope to include rdeps of this pkg. - if len(results) > 0 { - rdeps, err := snapshot.ReverseDependencies(ctx, allIDs[i], true) - if err != nil { - return err - } - for _, rdep := range rdeps { - scope[rdep.ID] = rdep - } + rdeps, err := snapshot.ReverseDependencies(ctx, allIDs[i], true) + if err != nil { + return err + } + mu.Lock() + defer mu.Unlock() + for _, rdep := range rdeps { + scope[rdep.ID] = rdep } // Add each corresponding method the to set of global search targets. |