Skip to content

Commit 5ce21f7

Browse files
committed
fix(events): harden nil context handling and thread ctx into rollback
Add a nil-context guard to EventContextFromContext so it returns nil instead of panicking on a nil ctx, and use the request-scoped ctx in rollbackDigestManifestTags for DeleteImageManifest/PutImageManifest so rollbacks honor cancellation and carry event metadata. Signed-off-by: cainydev <wajo432@gmail.com>
1 parent 8f4c119 commit 5ce21f7

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

pkg/extensions/events/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func WithEventContext(ctx context.Context, ec *EventContext) context.Context {
5050

5151
// EventContextFromContext retrieves the EventContext from a context.Context.
5252
func EventContextFromContext(ctx context.Context) *EventContext {
53+
if ctx == nil {
54+
return nil
55+
}
56+
5357
ec, _ := ctx.Value(eventContextKey{}).(*EventContext)
5458

5559
return ec

pkg/meta/hooks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func rollbackDigestManifestTags(ctx context.Context, repo string, tags, appliedM
9191

9292
for i := range slices.Backward(tags) {
9393
refTag := tags[i]
94-
if delErr := imgStore.DeleteImageManifest(context.Background(), repo, refTag, false); delErr != nil &&
94+
if delErr := imgStore.DeleteImageManifest(ctx, repo, refTag, false); delErr != nil &&
9595
!errors.Is(delErr, zerr.ErrManifestNotFound) {
9696
log.Error().Err(delErr).Str("repository", repo).Str("tag", refTag).
9797
Msg("multi-tag digest push: rollback DeleteImageManifest failed")
@@ -126,7 +126,7 @@ func rollbackDigestManifestTags(ctx context.Context, repo string, tags, appliedM
126126
continue
127127
}
128128

129-
if _, _, putErr := imgStore.PutImageManifest(context.Background(), repo, prior.digest.String(), prior.mediaType,
129+
if _, _, putErr := imgStore.PutImageManifest(ctx, repo, prior.digest.String(), prior.mediaType,
130130
restoreBody, []string{refTag}); putErr != nil {
131131
log.Error().Err(putErr).Str("repository", repo).Str("tag", refTag).
132132
Msg("multi-tag digest push: rollback restore prior manifest in store failed")

0 commit comments

Comments
 (0)