Skip to content

cmd/go: GOFLAGS=-modcacherw not honored when downloading toolchain for go.mod-triggered switch #81802

Open

Description

@karaolidis

Go version

go1.26.7 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-I/nix/store/hpkf5vc3qg0k5gzhdv6mmfyfs8b6yj55-krb5-1.22.1-dev/include'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/nikara/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/nikara/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS='-modcacherw'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2285042261=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/nikara/Projects/viya-risk-data/go.mod'
GOMODCACHE='/home/nikara/Projects/viya-risk-data/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB='*.sas.com,sassoftware.io'
GOOS='linux'
GOPATH='/home/nikara/Projects/viya-risk-data/.go'
GOPRIVATE=''
GOPROXY='goproxy.unx.sas.com'
GOROOT='/home/nikara/Projects/viya-risk-data/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.26.7.linux-amd64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/nikara/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/nikara/Projects/viya-risk-data/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.26.7.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.7'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

$ cat go.mod
module example.com/m

go 1.27.1

$ export GOPATH=$(mktemp -d) GOFLAGS=-modcacherw GOTOOLCHAIN=auto

$ go version
go: downloading go1.27.1 (linux/amd64)
go version go1.27.1 linux/amd64

$ ls -ld $GOPATH/pkg/mod/golang.org/toolchain@*
dr-xr-xr-x ... golang.org/toolchain@v0.0.1-go1.27.1.linux-amd64

What did you see happen?

All 1380 directories of the downloaded toolchain are read-only, so rm -rf fails. You need chmod -R u+w or go clean -modcache. Modules downloaded after the switch, with the same GOFLAGS, are writable.

What did you expect to see?

The toolchain directories should be writable, as with any other module downloaded under -modcacherw.

toolchain.Select runs before $GOFLAGS is applied in main.invoke, so cfg.ModCacheRW is still false when Exec downloads the toolchain. #64282 fixed this only for go install pkg@version and go run pkg@version.

Activity

  1. added a commit that references this issue on Sep 28, 2026
    1c24b95
  2. gopherbot commented on Sep 28, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/840205 mentions this issue: cmd/go: honor GOFLAGS=-modcacherw when downloading a toolchain

  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 29, 2026
  4. prattmic commented on Sep 29, 2026

    @prattmic
    Member

    cc @golang/command-line

  5. added this to the Backlog milestone on Oct 6, 2026
  6. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions