Skip to content

Commit f871472

Browse files
committed
internal/lsp/cache: lock in snapshot.knownFilesInDir
We were not locking while iterating s.files in snapshot.knownFilesInDir. All other accesses of s.files appear to be locked, so this should fix golang/go#43972. Fixes golang/go#43972 Change-Id: I01184c3992c91f8beb4a3239f70cc4487a528ec0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/287573 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org>
1 parent c2bea79 commit f871472

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

internal/lsp/cache/snapshot.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"golang.org/x/tools/internal/packagesinternal"
3333
"golang.org/x/tools/internal/span"
3434
"golang.org/x/tools/internal/typesinternal"
35-
"golang.org/x/xerrors"
3635
errors "golang.org/x/xerrors"
3736
)
3837

@@ -718,6 +717,9 @@ func (s *snapshot) allKnownSubdirs(ctx context.Context) map[span.URI]struct{} {
718717
// the given directory. It does not respect symlinks.
719718
func (s *snapshot) knownFilesInDir(ctx context.Context, dir span.URI) []span.URI {
720719
var files []span.URI
720+
s.mu.Lock()
721+
defer s.mu.Unlock()
722+
721723
for uri := range s.files {
722724
if source.InDir(dir.Filename(), uri.Filename()) {
723725
files = append(files, uri)
@@ -1010,7 +1012,7 @@ func (s *snapshot) awaitLoaded(ctx context.Context) error {
10101012

10111013
func (s *snapshot) GetCriticalError(ctx context.Context) *source.CriticalError {
10121014
loadErr := s.awaitLoadedAllErrors(ctx)
1013-
if xerrors.Is(loadErr, context.Canceled) {
1015+
if errors.Is(loadErr, context.Canceled) {
10141016
return nil
10151017
}
10161018

0 commit comments

Comments
 (0)