mirror of
https://github.com/moby/buildkit.git
synced 2026-06-24 08:47:57 +00:00
When a cleanup happens while a build is running it may cause boltdb record to be deleted while that record would have been used for cache export of the running build, causing the cache export to fail with Not Found error. This is possible because when cache is loaded to snapshots then snapshots are reference counted, protecting against them being released or deleted, but when cache key is just intermediary, the query result just gets saved and is used later. It should be safe to ignore this error and skip over the result if it doesn't exist anymore. Note that cache export also gets called on provenance creation because cache chains are used for finding remote descriptors for build steps. This was the more likely codepath for hitting this error. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
35 lines
779 B
Go
35 lines
779 B
Go
package solver
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCompareCacheRecord(t *testing.T) {
|
|
now := time.Now()
|
|
a := &CacheRecord{CreatedAt: now, Priority: 1}
|
|
b := &CacheRecord{CreatedAt: now, Priority: 2}
|
|
c := &CacheRecord{CreatedAt: now.Add(1 * time.Second), Priority: 1}
|
|
d := &CacheRecord{CreatedAt: now.Add(-1 * time.Second), Priority: 1}
|
|
|
|
records := []*CacheRecord{b, nil, d, a, c, nil}
|
|
slices.SortFunc(records, compareCacheRecord)
|
|
|
|
names := map[*CacheRecord]string{
|
|
a: "a",
|
|
b: "b",
|
|
c: "c",
|
|
d: "d",
|
|
nil: "nil",
|
|
}
|
|
var got []string
|
|
for _, r := range records {
|
|
got = append(got, names[r])
|
|
}
|
|
want := []string{"c", "a", "b", "d", "nil", "nil"}
|
|
if !slices.Equal(got, want) {
|
|
t.Fatalf("unexpected order: got %v, want %v", got, want)
|
|
}
|
|
}
|