Skip to content
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

x/tools/gopls: nil deref in evaluatePackageHandle (telemetry) #69236

Closed
adonovan opened this issue Sep 3, 2024 · 2 comments
Closed

x/tools/gopls: nil deref in evaluatePackageHandle (telemetry) #69236

adonovan opened this issue Sep 3, 2024 · 2 comments
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Sep 3, 2024

This stack kRRIIg was reported by telemetry:

We don't have a program counter, so we can't tell if it is succ or succ.ph that is nil. (We know n.ph.depKeys is non-nil.)

	reachable := b.s.pkgIndex.NewSet()
	for depID, succ := range n.succs {
		n.ph.depKeys[depID] = succ.ph.key // panic
		reachable.Add(succ.idxID)
crash/crash
runtime.gopanic:+69
runtime.panicmem:=262
runtime.sigpanic:+19
golang.org/x/tools/gopls/internal/cache.(*packageHandleBuilder).evaluatePackageHandle:+26
golang.org/x/tools/gopls/internal/cache.(*packageHandleBuilder).buildPackageHandle:+35
golang.org/x/tools/gopls/internal/cache.(*Snapshot).getPackageHandles.func2.1:+8
golang.org/x/sync/errgroup.(*Group).Go.func1:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)
golang.org/x/tools/gopls@v0.16.1 go1.23.0 darwin/arm64 other,vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Sep 3, 2024
@gopherbot gopherbot added this to the Unreleased milestone Sep 3, 2024
@hyangah hyangah modified the milestones: Unreleased, gopls/v0.17.0 Sep 4, 2024
@findleyr
Copy link
Member

I assert that I understand how this was possible, and that it has now been fixed (coincidentally) by refactoring.

Previously, we did not check handleNode.err before reading from succs. This meant that on context cancellation, there was a race in which we could try to read succ.ph even though succ.err was non-nil.

As part of a refactoring I performed recently, I changed evaluatePackageHandle to return an error, and that err terminates the errgroup. So this should no longer be a problem.
https://go-review.git.corp.google.com/c/tools/+/614164/12/gopls/internal/cache/check.go#1009

@findleyr findleyr self-assigned this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants