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: BundledQuickFixes bug reported by telemetry #64503

Closed
adonovan opened this issue Dec 1, 2023 · 5 comments
Closed

x/tools/gopls: BundledQuickFixes bug reported by telemetry #64503

adonovan opened this issue Dec 1, 2023 · 5 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 Dec 1, 2023

This stack CRoOPw was reported by telemetry:

	var fix quickFixesJSON
	if err := json.Unmarshal(*diag.Data, &fix); err != nil {
		bug.Reportf("unmarshalling quick fix: %v", err)
		return nil
	}
gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Reportf:1
golang.org/x/tools/gopls/internal/lsp/source.BundledQuickFixes:6
golang.org/x/tools/gopls/internal/lsp.(*Server).codeActionsMatchingDiagnostics:4
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction:92
golang.org/x/tools/gopls/internal/lsp.(*Server).CodeAction:1
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch:142
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3:5
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.handshaker.func4:52
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.MustReplyHandler.func1:2
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2.2:3
runtime.goexit:0
golang.org/x/tools/gopls@v0.14.2 go1.21.0 darwin/amd64 (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 Dec 1, 2023
@gopherbot gopherbot added this to the Unreleased milestone Dec 1, 2023
@adonovan
Copy link
Member Author

adonovan commented Dec 1, 2023

The diag.Data slice appears to be produced only from protocol.BundledFixes, which are sent from the server to the client and back, but should never produced or modified by the client. The code looks sound. My only hypotheses are:

  • a curious user or misbehaving client is sending home-made or invalid BundledFixes messages, or modifying the value before returning it to the server. Seems unlikely.
  • a diagnostic hash collision caused by the lack of proper framing around the binary blob, computeDiagnosticHash (it should be length-delimited). Seems astronomically unlikely.
  • a misbehaving client is sending a non-null but empty array for BundledFixes, which is not a valid JSON value. Possible?

@hyangah hyangah modified the milestones: Unreleased, gopls/v0.15.0 Dec 7, 2023
@findleyr
Copy link
Contributor

a misbehaving client is sending a non-null but empty array for BundledFixes, which is not a valid JSON value. Possible?

That seems probable. Note that the client in the link above is neovim. It may be worth trying to reproduce.
However, I looked at the neovim code and didn't see anything broken... (it appears that the diagnostic data is forwarded unmodified, and vim json decoding defaults to "omitempty" behavior: https://github.com/neovim/neovim/blob/69ffbb76c237fcbba24de80f1b5346d92642e800/runtime/lua/vim/lsp/diagnostic.lua#L127)

Nevertheless, this should probably not be a bug report since it involves the LSP client. Bug reports should be reserved for things that are definitely bugs.

@findleyr findleyr assigned findleyr and unassigned findleyr Dec 12, 2023
@findleyr
Copy link
Contributor

Upon consideration, I'm not sure what to do with this. I don't really want to turn this into an RPC error or a log. I think it warrants further investigation.

Since the report rate is low, let's leave it until v0.16.0.

@findleyr findleyr modified the milestones: gopls/v0.15.0, gopls/v0.16.0 Dec 12, 2023
@gopherbot
Copy link

Change https://go.dev/cl/549575 mentions this issue: gopls/internal/lsp/cache: allow "" or "null" Diagnostics.Data

@adonovan
Copy link
Member Author

That seems probable.

Ah, well in that case the fix is easy: permit "" or "null" JSON strings for the Diagnostic.Data value, and treat them both as "no data". I've sent you a CL.

Thanks.

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

4 participants