x/tools/internal/lsp/cache: fails to load packages with missing imports concurrently #35951
Labels
FrozenDueToAge
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
If
(*snapshot).PackageHandles
is called concurrently, the following race is possible:g1:
PackageHandles
starts, callsgetMetadataForURI
, and entersload
, which callspackages.Load
.g2: does the same.
g1:
packages.Load
finishes.load
re-reads metadata inside ofupdateMetadata
, then updates it. It returns all the way up toPackageHandles
and is fine.g2:
packages.Load
finishes.load
re-reads metadata inside ofupdateMetadata
. It observes the changes from g1, and invalidateMetadata
concludes that it does not need to recheck the package. It returnsnil
toPackageHandles
, indicating that it should use the previous metadata. Unfortunately, that previous metadata was read before g2 finished, and is empty.PackageHandles
then returns an error.Obviously the bug should be fixed. It might also make sense to deduplicate
load
calls at some level, or limit the number of outstandingpackages.Load
calls somehow.cc @stamblerre @ianthehat
The text was updated successfully, but these errors were encountered: