Skip to content

Commit c91d0b8

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent c0742f5 commit c91d0b8

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

gopls/internal/lsp/source/references.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,23 +393,27 @@ func expandMethodSearch(ctx context.Context, snapshot Snapshot, method *types.Fu
393393
if err != nil {
394394
return err
395395
}
396+
var mu sync.Mutex // guards scope and targets
396397
var group errgroup.Group
397398
for i, index := range indexes {
398399
i := i
399400
index := index
400401
group.Go(func() error {
401402
// Consult index for matching methods.
402403
results := index.Search(key, method.Name())
404+
if len(results) == 0 {
405+
return nil
406+
}
403407

404408
// Expand global search scope to include rdeps of this pkg.
405-
if len(results) > 0 {
406-
rdeps, err := snapshot.ReverseDependencies(ctx, allIDs[i], true)
407-
if err != nil {
408-
return err
409-
}
410-
for _, rdep := range rdeps {
411-
scope[rdep.ID] = rdep
412-
}
409+
rdeps, err := snapshot.ReverseDependencies(ctx, allIDs[i], true)
410+
if err != nil {
411+
return err
412+
}
413+
mu.Lock()
414+
defer mu.Unlock()
415+
for _, rdep := range rdeps {
416+
scope[rdep.ID] = rdep
413417
}
414418

415419
// Add each corresponding method the to set of global search targets.

0 commit comments

Comments
 (0)