Create the cancelable ctx from the context passed into the warm func
@@ -273,14 +273,14 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
awaitFetchers := &sync.WaitGroup{}
awaitFetchers.Add(len(toUpdate))
- ctxc, cancel := context.WithCancel(context.Background())
+ ctxc, cancel := context.WithCancel(ctx)
var once sync.Once
defer cancel()
updates:
for _, up := range toUpdate {
select {
- case <-ctx.Done():
+ case <-ctxc.Done():
break updates
case fetchers <- struct{}{}:
}
@@ -288,12 +288,6 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
go func(update update) {
defer func() { awaitFetchers.Done(); <-fetchers }()
- select {
- case <-ctxc.Done():
- return // terminate on error
- default: // avoid blocking
- }
-
imageID := update.ref
if w.Trace {
@@ -301,7 +295,7 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
}
// Get the image from the remote
- entry, err := client.Manifest(ctx, imageID.Tag)
+ entry, err := client.Manifest(ctxc, imageID.Tag)
if err != nil {
if err, ok := errors.Cause(err).(net.Error); ok && err.Timeout() {
// This was due to a context timeout, don't bother logging
