Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hyangah opened this issue Jun 10, 2024 · 2 comments
Closed

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

hyangah opened this issue Jun 10, 2024 · 2 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Jun 10, 2024

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

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 10, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jun 10, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.16.0 Jun 10, 2024
@findleyr findleyr self-assigned this Jun 10, 2024
@gopherbot
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants