-
Notifications
You must be signed in to change notification settings - Fork 567
CNTRLPLANE-3329: Fix gocacheprog cache corruption with atomic writes #8624
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: gocacheprog Tests (Reusable) | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: gocacheprog Unit Tests | ||
| runs-on: arc-runner-set | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | ||
| env: | ||
| HOME: /tmp | ||
| with: | ||
| go-version-file: contrib/ci/gocacheprog/go.mod | ||
| cache: false | ||
| - name: Run tests | ||
| run: cd contrib/ci/gocacheprog && go test -race -count=1 ./... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: gocacheprog Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - release-4.22 | ||
| paths: | ||
| - contrib/ci/gocacheprog/** | ||
|
|
||
| jobs: | ||
| test: | ||
| uses: openshift/hypershift/.github/workflows/gocacheprog-test-reusable.yaml@main | ||
| permissions: | ||
| contents: read | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "sync" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "sync/atomic" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -419,3 +420,63 @@ func TestConcurrentPutAndGet(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wg.Wait() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func TestConcurrentPutSameOutputID(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Parallel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rwDir := t.TempDir() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputID := mustDecodeHex(t, "7777777777777777") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body := []byte("shared output content that all writers agree on") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Seed one entry so GETs can find it while PUTs overwrite the data file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seedAction := mustDecodeHex(t, fmt.Sprintf("%016x", 2000)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seedReq := &request{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ID: 0, Command: "put", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ActionID: seedAction, OutputID: outputID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Body: body, BodySize: int64(len(body)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if resp := handlePut(seedReq, rwDir); resp.Err != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Fatalf("seed put: %s", resp.Err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Interleave PUTs (different ActionIDs, same OutputID) with GETs that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // read the data file via DiskPath. Without atomic writes, a PUT's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // O_TRUNC would momentarily zero the file, causing a reader to see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // truncated/empty content. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var wg sync.WaitGroup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var badReads atomic.Int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i := range 100 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wg.Add(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| go func() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer wg.Done() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| actionID := mustDecodeHex(t, fmt.Sprintf("%016x", i+2000)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| putReq := &request{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ID: int64(i), Command: "put", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ActionID: actionID, OutputID: outputID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Body: body, BodySize: int64(len(body)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if resp := handlePut(putReq, rwDir); resp.Err != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Errorf("put %d error: %s", i, resp.Err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| go func() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer wg.Done() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getReq := &request{ID: int64(i + 5000), Command: "get", ActionID: seedAction} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resp := handleGet(getReq, "", rwDir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if resp.Miss { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data, err := os.ReadFile(resp.DiskPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+463
to
+471
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Count GET misses and read errors as test failures. Right now this only increments 🔧 Suggested fix go func() {
defer wg.Done()
getReq := &request{ID: int64(i + 5000), Command: "get", ActionID: seedAction}
resp := handleGet(getReq, "", rwDir)
if resp.Miss {
+ badReads.Add(1)
return
}
data, err := os.ReadFile(resp.DiskPath)
if err != nil {
+ badReads.Add(1)
return
}
if string(data) != string(body) {
badReads.Add(1)
}
}()📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if string(data) != string(body) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| badReads.Add(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wg.Wait() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if n := badReads.Load(); n > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Errorf("got %d reads with corrupted data from concurrent PUT/GET on same OutputID", n) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 177
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 2943
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 1217
Pin reusable workflow reference to an immutable revision (avoid
@main).In
.github/workflows/gocacheprog-test.yaml, the job callsopenshift/hypershift/.github/workflows/gocacheprog-test-reusable.yaml@main(mutable), so CI won’t necessarily run the same reusable workflow revision deterministically. Use a local workflow reference (or a full commit SHA) instead.🔒 Proposed fix
🧰 Tools
🪛 zizmor (1.25.2)
[error] 13-13: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
🤖 Prompt for AI Agents