Skip to content

Tar errors on cache restore after toolchain installation #424

@matthewhughes-uw

Description

@matthewhughes-uw

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 #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.0
  • toolchain 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-amd64 are already present on the machine, causing errors from tar

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)

Activity

changed the title [-]Tar errors on cache restore with differing go and toolchain directives[/-] [+]Tar errors on cache restore after toolchain installation[/+] on Sep 15, 2023
dsame

dsame commented on Sep 15, 2023

@dsame
Contributor

Hello @matthewhughes-uw , thank you for the input. We are starting to investigate the problem.

self-assigned this
on Oct 16, 2023
linked a pull request that will close this issueRemove toolchain directories from the cache. #437on Oct 24, 2023
linked a pull request that will close this issue on Oct 24, 2023
linked a pull request that will close this issueRemove toolchain directories from the cache #438on Oct 24, 2023
thall

thall commented on Jan 8, 2024

@thall

Hello @matthewhughes-uw , thank you for the input. We are starting to investigate the problem.

do you have any updates around this to share?

23 remaining items

self-assigned this
on Oct 3, 2024
removed their assignment
on Nov 22, 2024
erikburt

erikburt commented on Jan 27, 2025

@erikburt

I'll chime in here to bump this thread, explain my issue, and a solution.

Situation:

  1. We had a go and different toolchain version specified in our go.mod.
  2. We had cache: false when calling this action.
  3. We were caching go modules separately for when installing/building our projects

Problem:

  1. Installing the go version (and not the toolchain) with this action
  2. Running a go command would then cache the toolchain's modules
  3. Running actions/cache on our go mod cache directory would
    • Saving: Caches the toolchain's modules
    • Restore: Attempt to extract the toolchain's modules over a directory that already contained them (The cause of the errors)

Solutions:

I think both of the solutions I've shown here are rather hacky and this action should support installing the toolchain version instead.

Solution 1: Installing the toolchain version if it exists

    - name: Get Go Version
      shell: bash
      id: go-version
      run: |
        version=$(sed -ne '/^toolchain /s/^toolchain go//p' ${{ inputs.go-version-file }})
        if [ -z "$version" ]; then
          version=$(sed -ne '/^go /s/^go //p' ${{ inputs.go-version-file }})
          echo "Toolchain version not found in ${{ inputs.go-version-file }}, using go directive instead."
        fi
        echo "Go Version: $version"
        echo "version=$version" >> "$GITHUB_OUTPUT"
    - name: Set up Go
      uses: actions/setup-go@v5.0.2
      with:
        go-version: ${{ steps.go-version.outputs.version }}
        cache: false
        check-latest: true

Full change here: fix: install toolchain version smartcontractkit/chainlink#15645

Solution 2: Suppressing tar errors with env var

    - name: Setup tar default options
      shell: bash
      # Do not overwrite existing files when extracting files from a cache archive.
      # Since actions/cache does not support this option, we set it here as a default.
      run: echo "TAR_OPTIONS=--skip-old-files" >> $GITHUB_ENV

self-assigned this
on Mar 20, 2025
lmvysakh

lmvysakh commented on Apr 11, 2025

@lmvysakh

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-files option 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:

- name: Setup tar default options
shell: bash
run: echo "TAR_OPTIONS=--skip-old-files" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

If you have any additional details or observations, feel free to share them here. Thanks again for your contribution!

matthewhughes-uw

matthewhughes-uw commented on Apr 14, 2025

@matthewhughes-uw
Author

If you have any additional details or observations, feel free to share them here. Thanks again for your contribution!

Per my comment above (#424 (comment)) I think the solution here is to avoid Go toolchain installs (since these are what cause the duplicate files), see also:

removed their assignment
on May 5, 2025
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @thall@dsame@timandy@lukeed@spencerschrock

      Issue actions

        Tar errors on cache restore after toolchain installation · Issue #424 · actions/setup-go