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: inconsistent behaviour with GOFLAGS=-mod=readonly set #36789

Closed
myitcv opened this issue Jan 27, 2020 · 5 comments
Closed

x/tools/gopls: inconsistent behaviour with GOFLAGS=-mod=readonly set #36789

myitcv opened this issue Jan 27, 2020 · 5 comments
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented Jan 27, 2020

What version of Go are you using (go version)?

$ go version
go version devel +73d213708e Sat Jan 25 16:34:18 2020 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20200124220429-8fe064f891f2
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.1.8-0.20200124220429-8fe064f891f2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/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-build912581415=/tmp/go-build -gno-record-gcc-switches"

What did you do?

We have a govim test that verifies the setting of the "env" value GOFLAG=-mod=readonly. It is based on the following setup:

-- go.mod --
module mod.com

go 1.13
-- main.go --
package main

import "example.com/blah"

func main() {
	println(blah.Name)
}

(example.com/blah is a valid module and is accessible).

We initially verify that we have the following diagnostic:

PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
    URI:         "file:///tmp/go-test-script844433945/script-config_set_env_goflags_mod_readonly/main.go",
    Version:     1,
    Diagnostics: {
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:2, Character:7},
                End:   protocol.Position{Line:2, Character:25},
            },
            Severity:           1,
            Code:               nil,
            Source:             "compiler",
            Message:            "could not import example.com/blah (no package for import example.com/blah)",
            Tags:               nil,
            RelatedInformation: nil,
        },
    },If applicable, copy/paste the text or add screenshots to help explain your problem.

}

However we often (~50% of the time, which is actually 100% of the time on CI, I can't reproduce locally) do not receive this diagnostic.

The following errors are logged by gopls:

Params: {"type":1,"message":"2020/01/26 21:52:32 diagnose: no workspace packages: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./... builtin]: exit status 1: build mod.com: cannot load example.com/blah: import lookup disabled by -mod=readonly\n\n\tdirectory = 0xa932b0"}

What's interesting is that when this test passes we do not see this or any errors logged by gopls.

Given I can't repro this locally it suggests there's an element of timing involved.

What did you expect to see?

Consistently receiving an initial diagnostic from gopls for main.go

What did you see instead?

As above.

Marking as v1.0.0 because this isn't critical for v0.3.0 to my mind.


cc @stamblerre

FYI @leitzler

@myitcv myitcv 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. labels Jan 27, 2020
@myitcv myitcv added this to the gopls/v0.3.0 milestone Jan 27, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 27, 2020
@stamblerre stamblerre modified the milestones: gopls/v0.3.0, gopls/v1.0.0 Jan 28, 2020
@stamblerre
Copy link
Contributor

Agreed that this is not critical for v0.3.0. It looks like we are getting the error message from the initialization go list and not presenting it as a diagnostic.

@stamblerre
Copy link
Contributor

@myitcv: Sorry for the delay on this. Is this still an issue with gopls at master?

@stamblerre stamblerre added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 9, 2020
@myitcv
Copy link
Member Author

myitcv commented Sep 10, 2020

@stamblerre - I've just submitted govim/govim@b1c1c85 to verify.

@maruel
Copy link
Contributor

maruel commented Sep 10, 2020

I did unrelated local testing and one thing I noticed is that if you run:

go env -w GOFLAGS="-mod=readonly"
go list

from a directory where the go.mod should normally be updated, first go list will print go: updates to go.mod needed, disabled by -mod=readonly but more importantly, it will exit with 1 instead of 0. That's likely what you're getting. I hope this helps.

@myitcv
Copy link
Member Author

myitcv commented Sep 15, 2020

@stamblerre I'm going to close this because we haven't had any flakes post me un-skipping that test. Obviously we can revisit if that situation changes.

@myitcv myitcv closed this as completed Sep 15, 2020
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.5.1 Sep 16, 2020
@golang golang locked and limited conversation to collaborators Sep 16, 2021
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants