Merge pull request #766 from noxiouz/fix_possible_goroutine_leak

[Client] Fix possible goroutine leak in pull
This commit is contained in:
Olivier Gambier 2014-11-20 16:41:48 -08:00
commit b7190a1e70

View file

@ -36,6 +36,11 @@ func Pull(c Client, objectStore ObjectStore, name, tag string) error {
errChans[i] = make(chan error)
}
// To avoid leak of goroutines we must notify
// pullLayer goroutines about a cancelation,
// otherwise they will lock forever.
cancelCh := make(chan struct{})
// Iterate over each layer in the manifest, simultaneously pulling no more
// than simultaneousLayerPullWindow layers at a time. If an error is
// received from a layer pull, we abort the push.
@ -45,13 +50,17 @@ func Pull(c Client, objectStore ObjectStore, name, tag string) error {
err := <-errChans[dependentLayer]
if err != nil {
log.WithField("error", err).Warn("Pull aborted")
close(cancelCh)
return err
}
}
if i < len(manifest.FSLayers) {
go func(i int) {
errChans[i] <- pullLayer(c, objectStore, name, manifest.FSLayers[i])
select {
case errChans[i] <- pullLayer(c, objectStore, name, manifest.FSLayers[i]):
case <-cancelCh: // no chance to recv until cancelCh's closed
}
}(i)
}
}