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: panic printing version info when using shimmed Go executable #38101

Closed
rliebz opened this issue Mar 27, 2020 · 6 comments
Closed
Labels
FrozenDueToAge 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

@rliebz
Copy link

rliebz commented Mar 27, 2020

What did you do?

On my machine I use the asdf version manager to manage my Go installation, which wraps the go executable with a shim. Using this setup, the latest version of gopls panics on several commands, such as gopls check.

I realize having to set up a version manager to debug is probably a pain, so I've managed to reproduce reliably in docker using docker run --rm -it debian:latest and the following steps:

#!/bin/bash

export GO111MODULE=on
export GOPATH=/go
export PATH=/go/bin:$PATH

# Install system dependencies
apt-get update && apt-get install -y git curl

# Install the latest Go version with asdf
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.8
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
. $HOME/.asdf/asdf.sh
asdf plugin add golang
asdf install golang 1.14.1
asdf global golang 1.14.1

# Install the latest version of gopls
go get golang.org/x/tools/gopls@master golang.org/x/tools@master

# Create a dummy go file and run gopls
touch main.go
gopls check main.go

What did you expect to see?

No panic, the command runs normally

What did you see instead?

A panic:

panic: err: exit status 1: stderr: unknown command: go. Perhaps you have to reshim?


goroutine 1 [running]:
golang.org/x/tools/internal/lsp/debug.PrintVersionInfo.func2()
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/debug/info.go:58 +0x1c3
golang.org/x/tools/internal/lsp/debug.section(0xe250c0, 0xc000032ea0, 0x0, 0xcc8d94, 0x7, 0xc00040aca0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/debug/info.go:69 +0x319
golang.org/x/tools/internal/lsp/debug.PrintVersionInfo(0xe37ec0, 0xc0000f2a50, 0xe250c0, 0xc000032ea0, 0x1, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/debug/info.go:52 +0x1a7
golang.org/x/tools/internal/lsp.(*Server).initialized(0xc0000ee200, 0xe37ec0, 0xc0000f2a50, 0x139ab58, 0x0, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/general.go:160 +0x1b0
golang.org/x/tools/internal/lsp.(*Server).Initialized(0xc0000ee200, 0xe37ec0, 0xc0000f2a50, 0x139ab58, 0xc000156380, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/server_gen.go:112 +0x49
golang.org/x/tools/internal/lsp/cmd.(*connection).initialize(0xc0000e3300, 0xe37ec0, 0xc0000f2a50, 0xd2ac08, 0xcbd140, 0xc0000f0ac0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/cmd/cmd.go:270 +0x314
golang.org/x/tools/internal/lsp/cmd.(*Application).connect(0xc0000b4280, 0xe37ec0, 0xc0000f27e0, 0x0, 0x0, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/cmd/cmd.go:202 +0x838
golang.org/x/tools/internal/lsp/cmd.(*check).Run(0xc00009a6c0, 0xe37ec0, 0xc0000f27e0, 0xc0000320b0, 0x1, 0x1, 0x0, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/cmd/check.go:45 +0xf2
golang.org/x/tools/internal/tool.Run(0xe37ec0, 0xc0000f27e0, 0xe3bd40, 0xc00009a6c0, 0xc0000320b0, 0x1, 0x1, 0x0, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/tool/tool.go:152 +0x29d
golang.org/x/tools/internal/lsp/cmd.(*Application).Run(0xc0000b4280, 0xe37ec0, 0xc0000f27e0, 0xc0000320b0, 0x2, 0x2, 0x0, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/lsp/cmd/cmd.go:146 +0x2cf
golang.org/x/tools/internal/tool.Run(0xe37e40, 0xc000038060, 0xe3bc80, 0xc0000b4280, 0xc0000320a0, 0x2, 0x2, 0x0, 0x0)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/tool/tool.go:152 +0x29d
golang.org/x/tools/internal/tool.Main(0xe37e40, 0xc000038060, 0xe3bc80, 0xc0000b4280, 0xc0000320a0, 0x2, 0x2)
	/go/pkg/mod/golang.org/x/tools@v0.0.0-20200326210457-5d86d385bf88/internal/tool/tool.go:91 +0x12f
main.main()
	/go/pkg/mod/golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88/main.go:25 +0xdb

Build info

golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.1.8-0.20200326210457-5d86d385bf88 h1:VHwe8L5z49UodPQ00s8OuYq5xk8LjagpydtFF7m+JCo=

Go info

go version go1.14.1 linux/amd64

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/.asdf/installs/golang/1.14.1/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/.asdf/installs/golang/1.14.1/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build386377116=/tmp/go-build -gno-record-gcc-switches"

Other Information

  • I've narrowed down the commit that first started panicking with a git bisect: 6fc5d0bc36fc9f0458937704b7b40bbcf4ea46bc.
  • Several other commands such as gopls format and gopls bug fail with the same error.
  • asdf uses a bash script as a shim to manage go rather than directly calling the executable. That script looks like this:
    #!/usr/bin/env bash
    # asdf-plugin: golang 1.14.1
    exec /root/.asdf/bin/asdf exec "go" "$@"
@gopherbot gopherbot added this to the Unreleased milestone Mar 27, 2020
@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 Mar 27, 2020
@gopherbot
Copy link
Contributor

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre stamblerre changed the title x/tools/gopls: Panic printing version info when using shimmed Go executable x/tools/gopls: panic printing version info when using shimmed Go executable Mar 27, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.0 Mar 27, 2020
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/225817 mentions this issue: internal/gocommand: only set working dir if it's not empty

@rliebz
Copy link
Author

rliebz commented Mar 27, 2020

I checked out the commit with the fix (8faa90c24300080d4754607f9d3d95d29b1cc818), but this appears to still be an issue.

The bug reproduces following the same steps in the issue description, or swapping the tools version @master for @8faa90c explicitly.

@stamblerre stamblerre reopened this Mar 27, 2020
@stamblerre
Copy link
Contributor

stamblerre commented Mar 27, 2020

Thanks for following up! Just mailed https://golang.org/cl/226257, which I hope might do the trick? If you could try it out before I merge it that'd be really helpful. The steps do so are:

$ git clone https://go.googlesource.com/tools
$ cd tools
$ git fetch "https://go.googlesource.com/tools" refs/changes/57/226257/3 && git cherry-pick FETCH_HEAD
$ cd gopls
$ go install

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/226257 mentions this issue: internal/gocommand: don't delete command's environment

@rliebz
Copy link
Author

rliebz commented Mar 27, 2020

I can confirm that that change fixes the panic.

Thanks for the quick response!

@golang golang locked and limited conversation to collaborators Mar 28, 2021
apstndb pushed a commit to apstndb/gotoolsdiff that referenced this issue Jan 11, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
This was causing crashes by setting the working directory to be empty.

Fixes golang/go#38062
Fixes golang/go#38101

Change-Id: I6d679ee1d5dcab914df3d565d83aa6de0dd74cb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225817
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
apstndb pushed a commit to apstndb/gotoolsdiff that referenced this issue Jan 11, 2025
My fix in CL 225817 introduced another bug :)

Fixes golang/go#38101

Change-Id: I3de1a051d3e86474c6aa0fb0e427a590438e2172
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226257
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

3 participants