gopls built at ae52477ae52477

Observed organize imports stuck (deadlocked) occasionally. In VS Code where the extension issues the "organizeImports" code action on save by default, the problem can be surfaced as the "Saving foo.go: Getting Code Actions from ..." popup form.

It started to occur after https://go.dev/cl/589975 but we think the CL is needed to address other problems.

From the goroutine dump, we tracked the following goroutine is waiting on the channels but there is no active producer goroutine.

1 @ 0x9f98f4e 0x9f63f1f 0x9f63b32 0xa6fa98b 0xa6f7617 0x9fd1441
#       0xa6fa98a       golang.org/x/tools/internal/imports.findImport+0x3ca                    /Users/hakim/release/tools/internal/imports/fix.go:1751
#       0xa6f7616       golang.org/x/tools/internal/imports.addExternalCandidates.func5+0x116   /Users/hakim/release/tools/internal/imports/fix.go:1238

One obvious bug is we can return too early before starting producers. https://github.com/golang/tools/blob/ae524770c657808d9d9bb7dc3a622c7104e345a5/internal/imports/fix.go#L1711

This type of race is hard to reproduce (depends on the timing, cpu power, # of candidates in go module cache) on different machines, but once it occurs, the user will likely experience the issue repeatedly. :-(

Comment From: gabyhelp

Similar Issues

  • https://github.com/golang/go/issues/41969
  • https://github.com/golang/go/issues/67824
  • https://github.com/golang/go/issues/43560
  • https://github.com/golang/go/issues/59216
  • https://github.com/golang/go/issues/45089

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: gopherbot

Change https://go.dev/cl/591756 mentions this issue: internal/imports: simplify concurrency in external candidate search