Skip to content

Commit a059382

Browse files
committed
gopls/internal/lsp/cache: fail workspace load on context cancellation
If the context was cancelled early during initialization, it was possible that all module load scopes get skipped, because ParseMod returns the context error. As a result, the subsequent load would succeed trivially, even though the context was cancelled. After analyzing the reinitialization codepath, it seems very plausible to encounter this race, and it explains the flakiness of TestReinitializeRepeatedly -- I have found nothing else that would explain the failure mode observed in logs, that the reload bypasses initialization. Fix this by returning when context errors are encountered. Fixes golang/go#57780 Change-Id: I3fb971503f280131c59146bc586da45dd2ed1126 Reviewed-on: https://go-review.googlesource.com/c/tools/+/495058 gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]>
1 parent e5c8d4d commit a059382

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

gopls/internal/lsp/cache/view.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,18 @@ func (s *snapshot) loadWorkspace(ctx context.Context, firstAttempt bool) (loadEr
752752
// errors.
753753
fh, err := s.ReadFile(ctx, modURI)
754754
if err != nil {
755-
if ctx.Err() == nil {
756-
addError(modURI, err)
755+
if ctx.Err() != nil {
756+
return ctx.Err()
757757
}
758+
addError(modURI, err)
758759
continue
759760
}
760761
parsed, err := s.ParseMod(ctx, fh)
761762
if err != nil {
762-
if ctx.Err() == nil {
763-
addError(modURI, err)
763+
if ctx.Err() != nil {
764+
return ctx.Err()
764765
}
766+
addError(modURI, err)
765767
continue
766768
}
767769
if parsed.File == nil || parsed.File.Module == nil {

0 commit comments

Comments
 (0)