setup-go: Tar errors on cache restore after toolchain installation
Description:
When the version of Go in the go directive of go.mod is different from the version in the toolchain directive there is a cache conflict which causes errors on cache extraction.
Note: I think this is related to, but different from https://github.com/actions/setup-go/issues/403 since that appears to be covering the situation where some other tool is also working on the cache, but this issue is purely for the action running on a hosted runner without any additional changes to the environment etc.
Action version:
actions/setup-go@v4
Platform:
- Ubuntu
- macOS (untested)
- Windows (untested)
Runner type:
- Hosted
- Self-hosted
Tools version:
go 1.21.0toolchain go1.21.1
Repro steps:
See repo https://github.com/matthewhughes-uw/setup-go-test/, very basic repo with a single workflow that just runs this action (https://github.com/matthewhughes-uw/setup-go-test/blob/main/.github/workflows/go.yaml):
First run of the action https://github.com/matthewhughes-uw/setup-go-test/actions/runs/6195831453/job/16821285537
- Installs Go 1.21.0 (version detected from
go-version-file - Go detects toolchain and performs a toolchain install of Go 1.21.1 (see output
go: downloading go1.21.1 (linux/amd64)) - This places some files under
../../../go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.1.linux-amd64 - Finds no existing cache, doesn’t try to extract anything
- Caches
/home/runner/go/pkg/mod(which contains the files above) and/home/runner/.cache/go-build
Second run of the action https://github.com/matthewhughes-uw/setup-go-test/actions/runs/6195844389/job/16821321968
- First two steps as above
- Finds an existing cache, attempts to extract it, but because of the toolchain installation step files under
../../../go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.1.linux-amd64are already present on the machine, causing errors fromtar
Expected behavior:
Caching of the toolchain is handled gracefully, no errors between runs that don’t contain any extra caching logic outside of what the action provides by default
Actual behavior:
Errors on cache extraction (see repro steps)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 12
- Comments: 15 (1 by maintainers)
Commits related to this issue
- chore(gha): fix macos action/setup-go@v4 cache miss. Set the same Go version as specified in the `go.mod` because of the issue below: - https://github.com/actions/setup-go/issues/424 Signed-off-by: ... — committed to terramate-io/terramate by i4ki 3 years ago
- chore(gha): fix macos action/setup-go@v4 cache miss. Set the same Go version as specified in the `go.mod` because of the issue below: - https://github.com/actions/setup-go/issues/424 Additionally, t... — committed to terramate-io/terramate by i4ki 3 years ago
- chore(gha): fix macos action/setup-go@v4 cache miss. Set the same Go version as specified in the `go.mod` because of the issue below: - https://github.com/actions/setup-go/issues/424 Additionally, t... — committed to terramate-io/terramate by i4ki 3 years ago
- chore(gha): fix macos action/setup-go@v4 cache miss. Set the same Go version as specified in the `go.mod` because of many similar issues related to the setup-go cache unable to work when go.mod speci... — committed to terramate-io/terramate by i4ki 3 years ago
- Avoid Toolchain download before cache download `go version` is run before downloading the cache, but if this is run with a version of `go` that triggers a Toolchain download[1], e.g. if the installed... — committed to matthewhughes-uw/setup-go by matthewhughes934 3 years ago
- chore(gha): fix macos action/setup-go@v4 cache miss. (#1417) ## What this PR does / why we need it: Set the same Go version as specified in the `go.mod` because of many similar issues related to ... — committed to terramate-io/terramate by i4ki 3 years ago
- Update go tests to use the version file instead of a hardcoded version This should ensure there isn't any issues around extracting from the archive https://github.com/actions/setup-go/issues/424 — committed to internetarchive/Zeno by NGTmeaty a year ago
do you have any updates around this to share?
The same issue for me. Only go1.23 has the problem.
https://github.com/timandy/gohack/actions/runs/10399737890
I found that disable cache can solve the problem.
I think this can be avoided by just telling
Goto use the local toolchain when runninggo versionbefore downloading the cache, see: https://github.com/actions/setup-go/pull/456I think there’s another can of worms/separate issue around which version of Go should this action use when a
toolchaindirective is present, e.g. at the moment if you specifygo-versionbut have ago.modspecifying a newer-version of Go I expect anygocommand will run using the toolchain version, which may be unexpectedNote: the toolchain download is not done by
setup-go, it’s done byGoitself, e.g.Then if you try to run a
gocommand using a version that doesn’t match thetoolchainthe toolchain will be downloaded (creating new caches to ensure we download the new toolchain, and not just silently use an existing one):So unless
setup-gois configured to use the go version (or perhaps, any newer version) specified in thetoolchaindirective then there will be this download.setup-gothen continues to use the version it was configured with to run any futuregocommands (which may just invoke the toolchain version in the background)EDIT: I’m not sure if
setup-gocould just set theGOTOOLCHAINenv var to ensure it always use the configured version (docs https://go.dev/doc/toolchain)(from a quick test this skipped any toolchain download)
The issue seems to be caused by the setup-go being confused about the difference in “Go” version and the newly introduced “Toolchain” version.
Per my comment above (https://github.com/actions/setup-go/issues/424#issuecomment-2044454425) I think the solution here is to avoid Go toolchain installs (since these are what cause the duplicate files), see also:
Hi @matthewhughes-uw,
Thank you for opening this issue and bringing this to our attention!
We are still investigating this as there are multiple related issues that we are consolidating alongside this one. Your input is very valuable in helping us address this comprehensively. We appreciate your patience as we work towards a resolution.
Meanwhile, As a workaround, you can use an environment variable to suppress tar errors specifically by setting
TAR_OPTIONS=--skip-old-files. This will help to resolve conflicts during cache extraction. The--skip-old-filesoption prevents tar from overwriting existing files when extracting files from a cache archive. This ensures that any existing files are not replaced, which can be useful in avoiding conflicts during concurrent cache operations.Below is a code snippet for your reference:
If you have any additional details or observations, feel free to share them here. Thanks again for your contribution!
You could also set the
GOTOOLCHAINenv var tolocal:see https://github.com/actions/setup-go/pull/460 for more details
There’s a mix of
Goandsetup-godownloading bits. What I understand from your previous point:setup-go, and ends with the lineSuccessfully set up Go version 1.21.1setup-gothen invokesgo(specifically/opt/hostedtoolcache/go/1.21.1/x64/bin/go) which triggers a download of the toolchain, this is the linego: downloading go1.21.6 (linux/amd64)go1.21.1: This issetup-godownloading the requested cache (notgodoing anything)toolchain@v0.0.1-go1.21.6.linux-amd64/exists in the cache (the toolchain downloaded from the 2nd step)So the issue is we populate some of
go1.21.1’sGOMODCACHEand then restore the cache, which then complains because there are already some files thereYou could remove the
toolchaindirective from yourgo.mod(unless you do have a requirement for a specific version of Go greater than what thegodirective specifies when working in the module, see https://go.dev/blog/toolchain#toolchain-management)@matthewhughes-uw Any updates on this? After updating to Go version:
We start having these warnings in the build: