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

setup-go action should allow for existing cache files #403

Open
2 of 5 tasks
shaunco opened this issue Jul 27, 2023 · 11 comments · May be fixed by #412
Open
2 of 5 tasks

setup-go action should allow for existing cache files #403

shaunco opened this issue Jul 27, 2023 · 11 comments · May be fixed by #412
Assignees
Labels
feature request New feature or request to improve the current logic

Comments

@shaunco
Copy link

shaunco commented Jul 27, 2023

Description:
On a self-hosted runner that is already caching tools, the v4 setup-go action attempts to call tar to extract its mod cache and ends up with a bunch of "Cannot open: File exists" errors, and eventually

Action version:
v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:
^1.20

Repro steps:

Run actions/setup-go@v4
  with:
    go-version: ^1.[2](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:2)0
    check-latest: false
    token: ***
    cache: true
  env:
    GO111MODULE: on
    GOPRIVATE: github.com/xyz/*
    SSH_AUTH_SOCK: /tmp/ssh-XXXXXX/agent.1965
    SSH_AGENT_PID: 1966
Setup go version spec ^1.20
Found in cache @ /opt/hostedtoolcache/go/1.20.6/x64
Added go to the path
Successfully set up Go version ^1.20
/opt/hostedtoolcache/go/1.20.6/x64/bin/go env GOMODCACHE
/opt/hostedtoolcache/go/1.20.6/x64/bin/go env GOCACHE
/home/runner/go/pkg/mod
/home/runner/.cache/go-build
Received 4194[3](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:3)0[4](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:4) of 9246941[5](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:5)4 (0.5%), 4.0 MBs/sec
Received 11324[6](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:6)208 of 924694154 (12.2%), 54.0 MBs/sec
Received 205520896 of 924694154 (22.2%), 65.3 MBs/sec
Received 3103[7](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:7)[8](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:8)4[9](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:9)6 of 924694154 (33.6%), 74.0 MBs/sec
Received 427819008 of 924694154 (46.3%), 81.6 MBs/sec
Received 536870912 of 924694154 (58.1%), 85.3 MBs/sec
Received 666894336 of 924694154 (72.1%), 90.8 MBs/sec
Received 771751936 of 924694154 (83.5%), 91.9 MBs/sec
Received 872415232 of 924694154 (94.3%), 92.3 MBs/sec
Received 924694154 of 924694154 ([10](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:10)0.0%), 93.3 MBs/sec
Cache Size: ~882 MB (924694[15](https://github.com/xyz/abc/actions/runs/123/job/123#step:5:16)4 B)
/usr/bin/tar -xf /home/runner/work/_temp/c44c4bfb-8a98-491b-b4a7-2f38e4fd677c/cache.tzst -P -C /home/runner/work/abc/abc--use-compress-program unzstd
/usr/bin/tar: ../../../go/pkg/mod/go.temporal.io/[email protected]/interceptor/tracing_interceptor.go: Cannot open: File exists
/usr/bin/tar: ../../../go/pkg/mod/go.temporal.io/[email protected]/interceptor/tracing_interceptor_test.go: Cannot open: File exists
.
.
.
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2
Cache is not found

Expected behavior:
Existing files should be ignored via the -k or --skip-old-files option on tar

Actual behavior:
Existing files are treated as errors.

@shaunco shaunco added bug Something isn't working needs triage labels Jul 27, 2023
@dusan-trickovic
Copy link
Contributor

Hello @shaunco ! Thank you for reporting the issue, we will investigate it and get back to you as soon as we have more info :)

@shaunco
Copy link
Author

shaunco commented Jul 28, 2023

Thanks @dusan-trickovic ! Not sure if it is related, but we also seem to end up with quite a few duplicate setup-go action caches that all have the same sha256 and need to be cleared out every few days:
image

@dsame dsame self-assigned this Jul 31, 2023
@dsame
Copy link
Contributor

dsame commented Jul 31, 2023

Hello @shaunco,
can you please try to disable caching for the action:

  - uses: actions/setup-go@v4
    with:
      go-version: '...'
      cache: false

this should solve the problem.

@bc-lee
Copy link

bc-lee commented Aug 1, 2023

Based on my understanding, go get downloads source codes with write permissions removed. As a result, extracting (tar -xf) cache files to GOPATH may cause errors. It would be helpful for setup-go to add write permissions to the cache directory before extracting and remove them after the process is complete.

@dsame
Copy link
Contributor

dsame commented Aug 1, 2023

@bc-lee Self-hosted runner preserves the cache and builds results so caching does not have sense for them, we should disable caching for them by default. Currently it can be turned off manually

@bc-lee
Copy link

bc-lee commented Aug 1, 2023

@dsame Aha, that makes sense. I'm not sure if changing the default based on where the runner is running (i.e., provided by GitHub or self-hosted) is a good idea. I think it would be much better for the user to explicitly specify that option.

@dsame dsame linked a pull request Aug 1, 2023 that will close this issue
2 tasks
@dsame dsame removed a link to a pull request Aug 2, 2023
2 tasks
@dsame
Copy link
Contributor

dsame commented Aug 15, 2023

Hello @bc-lee my motivation to have the different value of cache is to have the same omitted cache input for both github-hosted and self-hosted builds in the other case users have to have to diffrenet workflows

@dsame dsame added feature request New feature or request to improve the current logic and removed bug Something isn't working labels Aug 15, 2023
@dsame
Copy link
Contributor

dsame commented Aug 15, 2023

I changed this bug to feature request basing on

@jizi
Copy link

jizi commented Dec 1, 2023

Hi @dsame

Self-hosted runner preserves the cache and builds results so caching does not have sense for them

This is not always true. We use the ephemeral self-hosted runners so it would be great to have the cache available.
With cache: false I can see that the dependencies are downloaded always.

@HaraldNordgren
Copy link

HaraldNordgren commented Jan 17, 2024

@shaunco Any updates on this? After updating to Go version:

--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,8 @@
 module github.com/company/repo

-go 1.20
+go 1.21.1
+
+toolchain go1.21.6

 require (

We start having these warnings in the build:

/usr/bin/tar: ../../../go/pkg/mod/golang.org/[email protected]/lib/time/mkzip.go: Cannot open: File exists
/usr/bin/tar: ../../../go/pkg/mod/golang.org/[email protected]/lib/time/zoneinfo.zip: Cannot open: File exists
/usr/bin/tar: ../../../go/pkg/mod/golang.org/[email protected]/lib/time/README: Cannot open: File exists
...

nirs added a commit to nirs/kubectl-gather that referenced this issue Aug 20, 2024
When cache is enabled we always get warnings from tar:

    usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/doc.go: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/LICENSE: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/config.json: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/go.mod: Cannot open: File exists
    /usr/bin/tar: Exiting with failure status due to previous errors
    Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2

According to setup-go issue[1] the mitigation is to disable the cache.

[1] actions/setup-go#403
nirs added a commit to nirs/kubectl-gather that referenced this issue Aug 20, 2024
When cache is enabled we always get warnings from tar:

    usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/doc.go: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/LICENSE: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/config.json: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/go.mod: Cannot open: File exists
    /usr/bin/tar: Exiting with failure status due to previous errors
    Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2

According to setup-go issue[1] the mitigation is to disable the cache.

Strangely, when the cache is disabled, the setup-go step is adding go to
the cache:

    Adding to the cache ...
    Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64

[1] actions/setup-go#403
@nirs
Copy link

nirs commented Aug 21, 2024

This issue happens also in github runners, this is not a self-hosted runner issue.

Example build with default cache (true):

Setup go version spec 1.23
Attempting to download 1.23...
matching 1.23...
Acquiring 1.23.0 from https://github.com/actions/go-versions/releases/download/1.23.0-10380775229/go-1.23.0-linux-x64.tar.gz
Extracting Go...
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/ede30b59-03da-4f40-b1c7-e50aa2f73636 -f /home/runner/work/_temp/52775e24-4217-4781-b396-3ae24cd725b8
Successfully extracted go to /home/runner/work/_temp/ede30b59-03da-4f40-b1c7-e50aa2f73636
Adding to the cache ...
Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64
Added go to the path
Successfully set up Go version 1.23
/opt/hostedtoolcache/go/1.23.0/x64/bin/go env GOMODCACHE
/opt/hostedtoolcache/go/1.23.0/x64/bin/go env GOCACHE
/home/runner/go/pkg/mod
/home/runner/.cache/go-build
Cache Size: ~284 MB (29787[11](https://github.com/nirs/kubectl-gather/actions/runs/10480817785/job/29029131984#step:3:12)99 B)
/usr/bin/tar -xf /home/runner/work/_temp/1f736259-d577-4dc2-a865-52339ade7aaf/cache.tzst -P -C /home/runner/work/kubectl-gather/kubectl-gather --use-compress-program unzstd
Received 297871199 of 297871199 (100.0%), 284.1 MBs/sec
/usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/doc.go: Cannot open: File exists
/usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/LICENSE: Cannot open: File exists
/usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/config.json: Cannot open: File exists
/usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/go.mod: Cannot open: File exists
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2
Cache is not found
go version go1.23.0 linux/amd64

Example build with cache: false:

Setup go version spec 1.23
Attempting to download 1.23...
matching 1.23...
Acquiring 1.23.0 from https://github.com/actions/go-versions/releases/download/1.23.0-10380775229/go-1.23.0-linux-x64.tar.gz
Extracting Go...
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/8ee9a1ac-37a8-47f9-9ef2-e8ccbddc2d84 -f /home/runner/work/_temp/08068888-1378-4be4-9126-be5b4945adc6
Successfully extracted go to /home/runner/work/_temp/8ee9a1ac-37a8-47f9-9ef2-e8ccbddc2d84
Adding to the cache ...
Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64
Added go to the path
Successfully set up Go version 1.23
go version go1.23.0 linux/amd64

Note these confusing logs - only when cache is disabled:

Adding to the cache ...
Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64

Finally using cache: true setup-go took 12 seconds, and with cache: false 7 seconds.

nirs added a commit to nirs/kubectl-gather that referenced this issue Aug 22, 2024
When cache is enabled we always get warnings from tar:

    usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/doc.go: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/LICENSE: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/config.json: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/go.mod: Cannot open: File exists
    /usr/bin/tar: Exiting with failure status due to previous errors
    Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2

According to setup-go issue[1] the mitigation is to disable the cache.

Strangely, when the cache is disabled, the setup-go step is adding go to
the cache:

    Adding to the cache ...
    Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64

[1] actions/setup-go#403
nirs added a commit to nirs/kubectl-gather that referenced this issue Aug 22, 2024
When cache is enabled we always get warnings from tar:

    usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/doc.go: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/LICENSE: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/config.json: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/go.mod: Cannot open: File exists
    /usr/bin/tar: Exiting with failure status due to previous errors
    Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2

According to setup-go issue[1] the mitigation is to disable the cache.

Strangely, when the cache is disabled, the setup-go step is adding go to
the cache:

    Adding to the cache ...
    Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64

[1] actions/setup-go#403
nirs added a commit to nirs/kubectl-gather that referenced this issue Aug 22, 2024
When cache is enabled we always get warnings from tar:

    usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/doc.go: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/LICENSE: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/config.json: Cannot open: File exists
    /usr/bin/tar: ../../../go/pkg/mod/golang.org/x/telemetry/[email protected]/go.mod: Cannot open: File exists
    /usr/bin/tar: Exiting with failure status due to previous errors
    Warning: Failed to restore: "/usr/bin/tar" failed with error: The process '/usr/bin/tar' failed with exit code 2

According to setup-go issue[1] the mitigation is to disable the cache.

Strangely, when the cache is disabled, the setup-go step is adding go to
the cache:

    Adding to the cache ...
    Successfully cached go to /opt/hostedtoolcache/go/1.23.0/x64

[1] actions/setup-go#403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@dsame @shaunco @nirs @bc-lee @HaraldNordgren @jizi @dusan-trickovic and others