forked from TrueCloudLab/distribution
Merge pull request #766 from noxiouz/fix_possible_goroutine_leak
[Client] Fix possible goroutine leak in pull
This commit is contained in:
commit
b7190a1e70
1 changed files with 10 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue