Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Unexpected permission issue shows as error in vscode's checker on code without errors. #1914

Closed
harikb opened this issue Sep 5, 2018 · 7 comments

Comments

@harikb
Copy link

harikb commented Sep 5, 2018

After Go 1.11 upgrade, I see the following error message in vscode, under a particular .go file

go build runtime/cgo: open /usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied


$ ls -al /usr/local/go/pkg/darwin_amd64/runtime/cgo.a
-rw-r--r--  1 root  wheel  38330 Aug 24 13:44 /usr/local/go/pkg/darwin_amd64/runtime/cgo.a
$ ls -ald /usr/local/go/pkg/darwin_amd64
drwxr-xr-x  60 root  wheel  2040 Aug 24 13:46 /usr/local/go/pkg/darwin_amd64
$ ls -ald /usr/local/go/pkg
drwxr-xr-x  8 root  wheel  272 Aug 24 13:46 /usr/local/go/pkg
$ ls -ald /usr/local/go
drwxr-xr-x  19 root  wheel  646 Aug 24 13:46 /usr/local/go
$ ls -ald /usr/local
drwxr-xr-x  17 root  wheel  578 Sep  4 09:28 /usr/local

In some respects, this is similar to golang/go#24674 . It may as well be a Go installation issue, but I need help figuring out how to reproduce this error on the command line.

MacOSX 10.12.6 , V S Code Version 1.26.1

Steps to Reproduce:

  1. Removed /usr/local/go. Delete everything from $GOPATH/bin
  2. brew unlink go (To overcome issue mentioned in the Go ticket above)
  3. brew uninstall go
  4. brew uninstall --force go
  5. Install a fresh copy from golang.org MacOSX pkg
  6. Launch VS Code, remove & reinstall the Go extension and corresponding tools.
  7. Error is still visible.

Surprisingly, this particular file doesn't not even use CGO. Only imports are

import (
 	"context"
 	"fmt"
 	"net/http"
)

Build succeed outside of VS Code without any issue

$ go build
$ go clean -cache -testcache -modcache
$ go build
$ # <<-- No errors

No changes to the cgo.a file, as expected, since the build was run as a normal (non-root) user.

$ ls -al /usr/local/go/pkg/darwin_amd64/runtime/cgo.a
-rw-r--r--  1 root  wheel  38330 Aug 24 13:44 /usr/local/go/pkg/darwin_amd64/runtime/cgo.a
@BartWillems
Copy link

Same problem on Arch Linux

@sengo4hd
Copy link

sengo4hd commented Sep 8, 2018

vscode-go uses the -i flag to build.
I get the exact same error outside of vscode wihgo build -i.

The usage of the -i flag is not sugested anymore starting with go 1.10.
As seen in golang/go#24674 (comment) i'd
suggest to simply remove the flag starting with go 1.10 in vscode-go,
as the code builds correctly - and apparently as fast - without it.

FYI you can disable the vscode go build (and thus the error) with "go.buildOnSave": "off",
while waiting for a fix.

@ramya-rao-a
Copy link
Contributor

@harikb Can you see if #1464 helps?

@ramya-rao-a
Copy link
Contributor

@1e3oss The initial reason to use the -i flag when running go build was to speed up the process as the dependent packages didnt have to be rebuilt all the time. In Go 1.10 this is solved by the build cache.

But recently we have come to depend on the -i flag to ensure that the dependencies are installed as gocode provides support only for packages that are already installed.

So we would not be removing the flag by default until there is a good solution for gocode

But meanwhile, for the current problem, one can use the solution added for #1464 which is stop adding this flag using the go.installDependenciesWhenBuilding setting.

@ramya-rao-a
Copy link
Contributor

@harikb The above should solve your issue. If not, feel free to re-open this issue

@harikb
Copy link
Author

harikb commented Sep 11, 2018

Thank you @ramya-rao-a . Setting "go.installDependenciesWhenBuilding": false, seems to get rid of this problem. It worked for both cases of language-server on as well as off.

@Linuturk
Copy link

Adding a comment here as asked by @ramya-rao-a in Slack.

$ go version
go version go1.11 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xxx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/path/to/my/project/outside/of/gopath/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-build807570115=/tmp/go-build -gno-record-gcc-switches"

Installed from the tarball from golang.org.

When I enable the go.installDependenciesWhenBuilding I get this output:

/home/path/to/my/project/outside/of/gopath>Finished running tool: /usr/local/go/bin/go build -i -o /tmp/go-code-check.495537416 .
go build golang_org/x/crypto/cryptobyte/asn1: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/crypto/cryptobyte/asn1.a: permission denied
go build golang_org/x/net/dns/dnsmessage: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/net/dns/dnsmessage.a: permission denied
go build golang_org/x/crypto/curve25519: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/crypto/curve25519.a: permission denied
go build golang_org/x/crypto/internal/chacha20: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/crypto/internal/chacha20.a: permission denied
go build golang_org/x/crypto/poly1305: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/crypto/poly1305.a: permission denied
go build golang_org/x/text/transform: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/text/transform.a: permission denied
go build golang_org/x/text/unicode/bidi: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/text/unicode/bidi.a: permission denied
go build golang_org/x/net/http2/hpack: open /usr/local/go/pkg/linux_amd64/vendor/golang_org/x/net/http2/hpack.a: permission denied

I get the same error if I run a similar go build -i command outside of vscode.

No cgo in use for this project.

I did just transition this project to a go module.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants