mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-05 18:40:59 +00:00
Data race is being flagged because a goroutine is currently writing tar data into `atar`, and `assert.NotEmpty(atar)` performs internal structure reflection into the returned `io.PipeWriter` and violates its internal synchronization primitives. This assertion doesn't seem to add any value to the test compared to just reading the pipe, so it has been removed. Data race details (abbreviated): ``` ================== WARNING: DATA RACE Write at 0x00c00041fbc0 by goroutine 55: sync/atomic.CompareAndSwapInt32() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/runtime/race_amd64.s:361 +0xb sync/atomic.CompareAndSwapInt32() <autogenerated>:1 +0x18 sync.(*Mutex).Lock() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/sync/mutex.go:46 +0x28 io.(*pipe).write() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/io/pipe.go:81 +0x9e io.(*PipeWriter).Write() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/io/pipe.go:161 +0x46 archive/tar.(*Writer).Flush() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/archive/tar/writer.go:59 +0xcc archive/tar.(*Writer).WriteHeader() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/archive/tar/writer.go:71 +0x46 code.forgejo.org/forgejo/runner/v9/act/runner.actionCacheCopyFileOrDir() /home/mfenniak/Dev/forgejo-runner/act/runner/action_cache.go:203 +0xabd code.forgejo.org/forgejo/runner/v9/act/runner.GoGitActionCache.GetTarArchive.func2.1() /home/mfenniak/Dev/forgejo-runner/act/runner/action_cache.go:154 +0xa5 ... Previous read at 0x00c00041fbc0 by goroutine 9: reflect.typedmemmove() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/runtime/mbarrier.go:213 +0x0 reflect.packEface() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/reflect/value.go:136 +0xc5 reflect.valueInterface() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/reflect/value.go:1513 +0x179 reflect.Value.Interface() /home/mfenniak/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.linux-amd64/src/reflect/value.go:1484 +0x106 github.com/stretchr/testify/assert.isEmpty() /home/mfenniak/go/pkg/mod/github.com/stretchr/testify@v1.10.0/assert/assertions.go:735 +0x7f github.com/stretchr/testify/assert.NotEmpty() /home/mfenniak/go/pkg/mod/github.com/stretchr/testify@v1.10.0/assert/assertions.go:769 +0x56 github.com/stretchr/testify/assert.(*Assertions).NotEmpty() /home/mfenniak/go/pkg/mod/github.com/stretchr/testify@v1.10.0/assert/assertion_forward.go:1175 +0xb1 code.forgejo.org/forgejo/runner/v9/act/runner.TestActionCache.func1() /home/mfenniak/Dev/forgejo-runner/act/runner/action_cache_test.go:60 +0x21e ================== ``` <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/858): <!--number 858 --><!--line 0 --><!--description dGVzdDogcHJldmVudCBkYXRhIHJhY2UgZGV0ZWN0aW9uIGluIFRlc3RBY3Rpb25DYWNoZSBbc2tpcCBjYXNjYWRlXQ==-->test: prevent data race detection in TestActionCache [skip cascade]<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/858 Reviewed-by: Gusted <gusted@noreply.code.forgejo.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package runner
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
//nolint:gosec
|
|
func TestActionCache(t *testing.T) {
|
|
a := assert.New(t)
|
|
cache := &GoGitActionCache{
|
|
Path: os.TempDir(),
|
|
}
|
|
ctx := t.Context()
|
|
cacheDir := "nektos/act-test-actions"
|
|
repo := "https://code.forgejo.org/forgejo/act-test-actions"
|
|
refs := []struct {
|
|
Name string
|
|
CacheDir string
|
|
Repo string
|
|
Ref string
|
|
}{
|
|
{
|
|
Name: "Fetch Branch Name",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "main",
|
|
},
|
|
{
|
|
Name: "Fetch Branch Name Absolutely",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "refs/heads/main",
|
|
},
|
|
{
|
|
Name: "Fetch HEAD",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "HEAD",
|
|
},
|
|
{
|
|
Name: "Fetch Sha",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "de984ca37e4df4cb9fd9256435a3b82c4a2662b1",
|
|
},
|
|
}
|
|
for _, c := range refs {
|
|
t.Run(c.Name, func(t *testing.T) {
|
|
sha, err := cache.Fetch(ctx, c.CacheDir, c.Repo, c.Ref, "")
|
|
if !a.NoError(err) || !a.NotEmpty(sha) {
|
|
return
|
|
}
|
|
atar, err := cache.GetTarArchive(ctx, c.CacheDir, sha, "js")
|
|
if !a.NoError(err) {
|
|
return
|
|
}
|
|
defer atar.Close()
|
|
mytar := tar.NewReader(atar)
|
|
th, err := mytar.Next()
|
|
if !a.NoError(err) || !a.NotEqual(0, th.Size) {
|
|
return
|
|
}
|
|
buf := &bytes.Buffer{}
|
|
// G110: Potential DoS vulnerability via decompression bomb (gosec)
|
|
_, err = io.Copy(buf, mytar)
|
|
a.NoError(err)
|
|
str := buf.String()
|
|
a.NotEmpty(str)
|
|
})
|
|
}
|
|
}
|