From 8244761d2178b3ab4e3296c0245c94075a0f1c32 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 25 Feb 2025 09:26:59 -0800 Subject: [PATCH] fix trace blob detected as leaked blob in tests Trace blob is created 3 seconds after build completion. If this happens after test has cleaned all history records and before it checks for leaked blobs, test can report the trace blob as leaked. In practice it would be cleaned up next time containerd GC gets triggered. Signed-off-by: Tonis Tiigi --- control/control.go | 1 + snapshot/containerd/content.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/control/control.go b/control/control.go index a54425168..dd03c7567 100644 --- a/control/control.go +++ b/control/control.go @@ -311,6 +311,7 @@ func (c *Controller) ListenBuildHistory(req *controlapi.BuildHistoryRequest, srv func (c *Controller) UpdateBuildHistory(ctx context.Context, req *controlapi.UpdateBuildHistoryRequest) (*controlapi.UpdateBuildHistoryResponse, error) { if req.Delete { + c.history.Finalize(ctx, req.Ref) // ignore error err := c.history.Delete(ctx, req.Ref) return &controlapi.UpdateBuildHistoryResponse{}, err } diff --git a/snapshot/containerd/content.go b/snapshot/containerd/content.go index c50cc99ac..efbd9db6d 100644 --- a/snapshot/containerd/content.go +++ b/snapshot/containerd/content.go @@ -115,7 +115,20 @@ func (c *nsFallbackStore) Update(ctx context.Context, info content.Info, fieldpa } func (c *nsFallbackStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error { - return c.main.Walk(ctx, fn, filters...) + seen := make(map[digest.Digest]struct{}) + err := c.main.Walk(ctx, func(i content.Info) error { + seen[i.Digest] = struct{}{} + return fn(i) + }, filters...) + if err != nil { + return err + } + return c.fb.Walk(ctx, func(i content.Info) error { + if _, ok := seen[i.Digest]; ok { + return nil + } + return fn(i) + }, filters...) } func (c *nsFallbackStore) Delete(ctx context.Context, dgst digest.Digest) error {