Break update on context cancel and set wait group increment after the select
@@ -271,7 +271,6 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
// w.Burst, so limit the number of fetching goroutines to that.
fetchers := make(chan struct{}, w.burst)
awaitFetchers := &sync.WaitGroup{}
- awaitFetchers.Add(len(toUpdate))
ctxc, cancel := context.WithCancel(ctx)
var once sync.Once
@@ -280,11 +279,13 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
updates:
for _, up := range toUpdate {
select {
- case <-ctx.Done():
+ case <-ctxc.Done():
break updates
case fetchers <- struct{}{}:
}
+ awaitFetchers.Add(1)
+
go func(update update) {
defer func() { awaitFetchers.Done(); <-fetchers }()
