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

gopls: time.Format with the bad format "2006-02-01" causes gopls to hang (new analyzer) #2406

Closed
Phadin opened this issue Aug 12, 2022 · 11 comments
Assignees
Milestone

Comments

@Phadin
Copy link

Phadin commented Aug 12, 2022

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.19 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.70.1 (Universal)
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.35.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    go: /usr/local/bin/go: go version go1.19 darwin/amd64
    gotests: not installed
    gomodifytags: not installed
    impl: not installed
    goplay: not installed
    dlv: /Users/mbarri202/go/bin/dlv (version: v1.9.0 built with go: go1.19)
    staticcheck: /Users/mbarri202/go/bin/staticcheck (version: v0.3.3 built with go: go1.19)
    gopls: /Users/mbarri202/go/bin/gopls (version: v0.9.3 built with go: go1.19)

Describe the bug

Intellisense/gopls dies when using custom time format with time.Format. Go: Restart Language Server will work to restore functionality only if the offending code is removed or there are code errors preventing it from being run through. When the error occurs, hovering over text is stuck with a 'loading...' box, saving will hang on trying to access go formatting, and autocomplete will not function.

Steps to reproduce the behavior:

Go code that will cause the error:

now := time.Now()
nowFormatted := now.Format("2006-02-01")
fmt.Printf("Time: %v", nowFormatted)

Note that no error occurs with other time.Format functions such as now.Format(time.RFC822). It seemed to only occur with this custom format.

@gopherbot gopherbot added this to the Untriaged milestone Aug 12, 2022
@findleyr
Copy link
Member

Hi, thank you for reporting. I was not able to reproduce following your instructions. Can you please attach the panicking stack? (you can find this via output -> gopls (server)).

@findleyr
Copy link
Member

Wait, I do believe I can reproduce: I don't get a crash, but rather a hanging process.

I am investigating.

@findleyr
Copy link
Member

Well, yes it is reliably reproducible, and only with that format.

Almost certainly this is related to https://go.dev/cl/354010. Note that the format "2006-02-01" is likely wrong, per the discussion in https://go.dev/issue/48801. But of course it should not make gopls hang.

CC @timothy-king (Tim: no action required from you, just keeping you informed that there may be a bug in this analyzer).

Amazing that this was caught so soon. Thank you very much for filing an issue!

@findleyr
Copy link
Member

The root cause is a debug print statement left in the analyzer, which breaks gopls' communication over stdin/stdout.

@eqinox76
Copy link

Hit the same issue with time.Format("2006-02-01 15:04:05").
Kudos for adding this check even if the print statement is unfortunate.

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/422902 mentions this issue: go/analysis: remove stray print statement in the timeformat analyzer

@findleyr findleyr changed the title time.Format with custom format crashing Intellisense/gopls. gopls: time.Format with the bad format "2006-02-01" causes gopls to hang (new analyzer) Aug 12, 2022
@findleyr findleyr self-assigned this Aug 12, 2022
@findleyr
Copy link
Member

Reopening and pinning until this is released.

Since it is Friday, we likely won't cut a new release until Monday.

@findleyr findleyr reopened this Aug 12, 2022
@findleyr findleyr pinned this issue Aug 12, 2022
@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/422903 mentions this issue: go/analysis: remove stray print statement in the timeformat analyzer

gopherbot pushed a commit to golang/tools that referenced this issue Aug 12, 2022
…in the timeformat analyzer

A debugging print statement was left in the analyzer, which breaks
gopls' communication over stdin/stdout.

Fix this, and add tests.

Also add back the x/tools replace target, so that tests pass.

For golang/vscode-go#2406

Change-Id: I1b785fa09e66eae2f1b1e03806e5b59d2015e75e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422902
TryBot-Result: Gopher Robot <[email protected]>
gopls-CI: kokoro <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
Reviewed-by: Tim King <[email protected]>
(cherry picked from commit bebd890)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422903
Reviewed-by: Suzy Mueller <[email protected]>
@findleyr
Copy link
Member

The fix for this issue will be released on Monday (we don't do releases late in the day on Friday, I'm afraid).

In the meantime, anyone encountering this bug can take any one of the following mitigating steps:

@Phadin
Copy link
Author

Phadin commented Aug 15, 2022

Thank you for the quick verification and work on releasing a fix.

@findleyr
Copy link
Member

findleyr commented Aug 15, 2022

This fix has been released in [email protected].

@findleyr findleyr unpinned this issue Aug 15, 2022
@golang golang locked and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants