Skip to content

x/tools/gopls: stuck organizeImports code action #67923

Closed
@hyangah

Description

@hyangah

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. :-(

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions