From 2071422bea9f98a0e5258786b89caa1b0c145509 Mon Sep 17 00:00:00 2001 From: Anton Tiurin Date: Fri, 21 Nov 2014 11:20:16 +0300 Subject: [PATCH] [Client] Fix possible goroutine leak in push. The same as 5a804ac05bc3facd61953908da99310a257727a1 --- client/push.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/push.go b/client/push.go index 91bd9af6..08726058 100644 --- a/client/push.go +++ b/client/push.go @@ -36,6 +36,8 @@ func Push(c Client, objectStore ObjectStore, name, tag string) error { errChans[i] = make(chan error) } + cancelCh := make(chan struct{}) + // Iterate over each layer in the manifest, simultaneously pushing no more // than simultaneousLayerPushWindow layers at a time. If an error is // received from a layer push, we abort the push. @@ -45,13 +47,17 @@ func Push(c Client, objectStore ObjectStore, name, tag string) error { err := <-errChans[dependentLayer] if err != nil { log.WithField("error", err).Warn("Push aborted") + close(cancelCh) return err } } if i < len(manifest.FSLayers) { go func(i int) { - errChans[i] <- pushLayer(c, objectStore, name, manifest.FSLayers[i]) + select { + case errChans[i] <- pushLayer(c, objectStore, name, manifest.FSLayers[i]): + case <-cancelCh: // recv broadcast notification about cancelation + } }(i) } }