Skip to content

Commit f701b3b

Browse files
committed
Fix race in ctr pull
Signed-off-by: Derek McGowan <[email protected]>
1 parent e017143 commit f701b3b

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

cmd/ctr/commands/content/fetch.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ Most of this is experimental and there are few leaps to make this work.`,
6161
var (
6262
ref = clicontext.Args().First()
6363
)
64-
_, err := Fetch(ref, clicontext)
64+
client, ctx, cancel, err := commands.NewClient(clicontext)
65+
if err != nil {
66+
return err
67+
}
68+
defer cancel()
69+
70+
_, err = Fetch(ctx, client, ref, clicontext)
6571
return err
6672
},
6773
}
6874

6975
// Fetch loads all resources into the content store and returns the image
70-
func Fetch(ref string, cliContext *cli.Context) (containerd.Image, error) {
71-
client, ctx, cancel, err := commands.NewClient(cliContext)
72-
if err != nil {
73-
return nil, err
74-
}
75-
defer cancel()
76-
76+
func Fetch(ctx context.Context, client *containerd.Client, ref string, cliContext *cli.Context) (containerd.Image, error) {
7777
resolver, err := commands.GetResolver(ctx, cliContext)
7878
if err != nil {
7979
return nil, err

cmd/ctr/commands/images/pull.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,20 @@ command. As part of this process, we do the following:
5757
if ref == "" {
5858
return fmt.Errorf("please provide an image reference to pull")
5959
}
60-
ctx, cancel := commands.AppContext(context)
60+
61+
client, ctx, cancel, err := commands.NewClient(context)
62+
if err != nil {
63+
return err
64+
}
6165
defer cancel()
6266

63-
img, err := content.Fetch(ref, context)
67+
ctx, done, err := client.WithLease(ctx)
68+
if err != nil {
69+
return err
70+
}
71+
defer done(ctx)
72+
73+
img, err := content.Fetch(ctx, client, ref, context)
6474
if err != nil {
6575
return err
6676
}

0 commit comments

Comments
 (0)