Skip to content

Commit

Permalink
internal/lsp/cache: lock in snapshot.knownFilesInDir
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr committed Jan 28, 2021
1 parent c2bea79 commit f871472
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/lsp/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"golang.org/x/tools/internal/packagesinternal"
"golang.org/x/tools/internal/span"
"golang.org/x/tools/internal/typesinternal"
"golang.org/x/xerrors"
errors "golang.org/x/xerrors"
)

Expand Down Expand Up @@ -718,6 +717,9 @@ func (s *snapshot) allKnownSubdirs(ctx context.Context) map[span.URI]struct{} {
// the given directory. It does not respect symlinks.
func (s *snapshot) knownFilesInDir(ctx context.Context, dir span.URI) []span.URI {
var files []span.URI
s.mu.Lock()
defer s.mu.Unlock()

for uri := range s.files {
if source.InDir(dir.Filename(), uri.Filename()) {
files = append(files, uri)
Expand Down Expand Up @@ -1010,7 +1012,7 @@ func (s *snapshot) awaitLoaded(ctx context.Context) error {

func (s *snapshot) GetCriticalError(ctx context.Context) *source.CriticalError {
loadErr := s.awaitLoadedAllErrors(ctx)
if xerrors.Is(loadErr, context.Canceled) {
if errors.Is(loadErr, context.Canceled) {
return nil
}

Expand Down

0 comments on commit f871472

Please sign in to comment.