-
Notifications
You must be signed in to change notification settings - Fork 752
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
bug: unable to determine go version
with Go installed using Snap
#166
Comments
@eqinox76 What is the output of |
Hey @hyangah
|
go version
with Go installed using Snap
I am not sure if snap is the issue here. Checking the version string from the official docker container is looks the same:
The log message may be a red hering. As the tooling installation, code completion, etc. is working fine. |
We've actually had a few reports of people using Snap and having issues with the |
Does it maybe have something to do with the way snap is aliasing binaries? $ whereis go
go: /snap/bin/go /snap/bin/go.gofmt
$ go version
go version go1.14.7 linux/amd64
$ ls -l /snap/bin/go
lrwxrwxrwx 1 root root 13 Aug 12 15:45 /snap/bin/go -> /usr/bin/snap |
Change https://golang.org/cl/248858 mentions this issue: |
Do you still see the issue with the latest version of the extension? From the log included in the original report, it looks like when the go extension ran |
And, invoke the go version command in the tool execution environment. Updates #166 Change-Id: I8e52035f2576af91ef7e987f7138805169d2c453 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/248858 Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org>
I have manually applied your patch above to my local instance, here are the outputs:
|
I am not sure how the version outputs differ: $ /snap/bin/go version
go version go1.14.7 linux/amd64
$ /usr/local/go/bin/go version
go version go1.15 linux/amd64 Could it be because both |
Sorry, any leads on that one? It's really quite an annoying bug. |
@dim Sorry, I am not familiar with Snap's permission and security model. We can disable all the go version related logic when In the original report -
I suspect the extension is not able to run the go command at all.
|
@hyangah sorry, I may not have all the answers on the snap security model as I am neither particularly familiar with it, but following your advise:
As explained before, in the Go channel, I can only see this: unable to determine version from the output of "/snap/bin/go version": ""
cached Go version ({"binaryPath":"/snap/bin/go","version":""}) is invalid, recomputing Running version command manually inside the vscode terminal seems to yield correct results: $ go version
go version go1.14.7 linux/amd64
$ /snap/bin/go version
go version go1.14.7 linux/amd64 I am not sure what else I should check. If it helps, I am more than happy to apply another manual patch to |
OK, looks like there is more to it: $ node -e 'require("child_process").execFile("/snap/bin/go", ["version"], (err, stdout, stderr) => { console.log(err, stdout, stderr) })'
null
$ node -e 'require("child_process").execFile("/usr/local/go/bin/go", ["version"], (err, stdout, stderr) => { console.log(err, stdout, stderr) })'
null go version go1.15 linux/amd64 Seems to be related to nodesource/distributions#663 |
So until we get a fix (I guess similar to what the code-sync guys did), we can use this workaround in our settings:
|
That was the missing needed miracle. |
Thank you for the workaround! |
in settings.json { |
https://github.com/snapcore/snapd/blob/master/cmd/snap/main.go#L478 Snap cares about calling it from a symlink, since it uses the symlink name to determine the command to run. I can't confirm this in vscode-go, but if it's resolving the alias before exec'ing it, it's likely losing the alias required to make 'snap' work correctly (which is why vscode reports snap, not the alias for go in the error). I'm not enough of a node expert to tell, but if this ( https://github.com/golang/vscode-go/blob/master/src/util.ts#L358 ) is traversing the symlink to the binary and then (edit) NOT passing the traversed path as argv[0] ( https://opensource.com/article/19/5/how-write-good-c-main-function ) to snap, it will break snap's ability to lookup which command is being called. Looking at ( https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options ), it appears you could pass in the ARGV name if it's a symlink, but not if it's a hardlink / process. Maybe? A previous version of this was closed without resolution : microsoft/vscode#75581 |
@mreynolds I am not sure if I understand your comment correctly - Do you mean that the workaround suggested by @diiimo2k20 or @ozzono is not working? I was about to send a cl to automatically replace My understanding so far is that the underlying issue is nodesource/distributions#663 and https://bugs.launchpad.net/snapd/+bug/1835805. The extension is passing whatever it finds from |
@hyangah I wasn't clear, I was meaning to say that the workaround is successful, because it's linking to a different binary than what Snap seems to install on the system path. The linked Snap code reads the ARGV to determine which code to actually run, and that seemed to be what's failing.
vs
That work-around works A-OK, I was more suggesting (again, not a node expert) that the issue is the ARGV that Snap is expecting that's somehow not coming through the exec call linked. The workaround links to internals inside Snap ( https://snapcraft.io/docs/commands-and-aliases ), which appear to have differences across linux distros : And there is a known issue in their forums about this topic (admittedly, from a different source) : https://forum.snapcraft.io/t/symlinks-and-snap-bin-structure/16532 Just a guess. I don't have the time or chops to try it myself. This is probably specific to the requirements of Snap, but Snap is super-popular... I used the workaround too. |
Thanks for the detailed explanation @mreynolds - that's fascinating and convincing. Strangely, things work without any issue out of box, so I am puzzled.
and Then, opened |
Looks like something somewhere is fixed now. 🤔
|
If I remove the workaround and try again, I get :
and I see what you see :
Looking at ( Line 358 in e6ab6f4
vscode-go/src/utils/pathUtils.ts Line 63 in e6ab6f4
So, I agree, doesn't look like an exec issue, it might just be an invalid cache issue due to the combo of the FIXIT and the passed in path? This logic seems to lack a check to recover from a broken invalid cache (it just warns and then returns the incorrect result, but never seems to invalidate the incorrect result) : Lines 368 to 376 in e6ab6f4
Meaning, it appears you can leave getGoVersion() with an invalid cached version after a failed attempt to resolve the version. |
@mreynolds Thanks for taking a look - but the FIXIT note is relevant only if you change |
I've got the same issue on Everything works fine with extension os: Ubuntu 20.10 |
Thanks @gigi214 - unfortunately, I don't use snap and have troubles reproducing this issue. v0.24.x contains a relatively small number of changes (v0.23.3...v0.24.0). #1344 is the only code that directly touching related code paths (instead of Can you try to add |
Sure, @hyangah.
here the
The issue is still present, and as side effect I haven't the lint, the autocompletition and all the advantages of the extension. |
Thank you @hyangah for the pointers how to run the debug log. It immediately revealed a culprit for similar issues on my setup. I too experienced this problem. It turned out that my global settings.json was referring old version of go (goroot) that was no longer on my disk. I changed it to the link of the current version and things seem to have improved.
This is what the /snap/go folder looks like
|
The problem is described here: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1849753 So this workaround also fixes the problem. |
I don't know to what extent this work, but it removed those annoying popups every time i save a go file thanks @diiimo2k20 for the Solution
combined with
Worked For Me VS Code
Go
OS
|
The problem might be that
|
This may be related to the fact that both vscode and go run as snaps (with classic confinement, but still). As a design decision, snaps cannot run other snaps in order to avoid undeclared dependencies. |
finally worked thanks!!!! |
This is still an ongoing issue in Ubuntu 22.04.2 |
I have this issue on a remote (ssh) unprivileged LXD/LXC container with Ubuntu 22.04.2 LTS and the snap installed Go version go1.20.3. However, if I install the same version of Go on its underlying remote Ubuntu 22.04.2 LTS host, I don't have the issue there. Btw. in the container I'm using the suggested go.alternateTools workaraound and that is ok for me. |
This workaround was still necessary in mid-2023 on a brand new Ubuntu Studio 22.04 LTS Jammy Jellyfish VM, running Go version 1.20.3. |
Popping up again on Ubuntu 23.04. "snap crap" |
Even if we can't fix the bug, it may be worth making VS Code detect when there's trouble invoking the go command at /snap/bin/go, and provide a hint to use alternateTools and a link to this issue. |
https://go-review.googlesource.com/c/vscode-go/+/545915 added path adjustment code (if the path acquired from |
What version of Go, VS Code & VS Code Go extension are you using?
go version
to get version of Gocode -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders5763d909d5f12fe19f215cbfdd29a91c0fa9208a
x64
go env
to get the go development environment detailsGOARCH="amd64"
GOBIN=""
GOCACHE="/home/carsten/.cache/go-build"
GOENV="/home/carsten/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/carsten/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/5830"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/5830/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/carsten/projects/TickImporter/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build126575450=/tmp/go-build -gno-record-gcc-switches"
Share the Go related settings you have added/edited
Describe the bug
Using the 'run test' annotation or the
Go: Test Package
does nothing.Steps to reproduce the behavior:
The output of gopls and go show no issues.
Running this exact command via the commandline works fine. Also from the terminal within vscode.
Checking the developer tools i only see the following warning:
When i watch the Process Explorer closely i see the the
go test
process starting and a subprocess for the linker for a very short time. I did not manage to capture a screenshot.I am running ubuntu 20.04 and have go and vscode installed via snap. I am using gopls as can be seen in the config above.
Any hints how i can debug this issue further?
The text was updated successfully, but these errors were encountered: