From 16e98936175c7d077b83b0bc8b3226ac17121d36 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Tue, 29 Aug 2023 16:47:18 -0500 Subject: [PATCH 1/2] fix: check snapshot labels to avoid panic I saw a panic while using the stargz snapshotter caused by the labels being nil. This adds a check to prevent the panic. Signed-off-by: Chris Goller --- cache/refs.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cache/refs.go b/cache/refs.go index 08a1de59d7f0..04ce918c5861 100644 --- a/cache/refs.go +++ b/cache/refs.go @@ -1099,8 +1099,10 @@ func (sr *immutableRef) prepareRemoteSnapshotsStargzMode(ctx context.Context, s if err == nil { // usable as remote snapshot without unlazying. defer func() { // Remove tmp labels appended in this func - for k := range tmpLabels { - info.Labels[k] = "" + if info.Labels != nil { + for k := range tmpLabels { + info.Labels[k] = "" + } } if _, err := r.cm.Snapshotter.Update(ctx, info, tmpFields...); err != nil { bklog.G(ctx).Warn(errors.Wrapf(err, From 395e72c52b12f5e87ba4149f3ec559a02600de20 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Thu, 31 Aug 2023 08:37:58 -0500 Subject: [PATCH 2/2] fix: log context for future debugging Signed-off-by: Chris Goller --- cache/refs.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cache/refs.go b/cache/refs.go index 04ce918c5861..2d7cbc1ca45b 100644 --- a/cache/refs.go +++ b/cache/refs.go @@ -1103,6 +1103,13 @@ func (sr *immutableRef) prepareRemoteSnapshotsStargzMode(ctx context.Context, s for k := range tmpLabels { info.Labels[k] = "" } + } else { + // We are logging here to track to try to debug when and why labels are nil. + // Log can be removed when not happening anymore. + bklog.G(ctx). + WithField("snapshotID", snapshotID). + WithField("name", info.Name). + Debug("snapshots exist but labels are nil") } if _, err := r.cm.Snapshotter.Update(ctx, info, tmpFields...); err != nil { bklog.G(ctx).Warn(errors.Wrapf(err,