Skip to content

Commit

Permalink
gopls/internal/lsp/source: guard against concurrent writes in xrefs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr committed Mar 6, 2023
1 parent c0742f5 commit c91d0b8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions gopls/internal/lsp/source/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,23 +393,27 @@ 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
index := index
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.
Expand Down

0 comments on commit c91d0b8

Please sign in to comment.