From de35ef2ebed3a7e8173abae39933d04e9874790c Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 18 Feb 2015 18:45:39 -0800 Subject: [PATCH] Avoid parallel layer downloads in load command Signed-off-by: Doug MacEachern --- graph/load.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/graph/load.go b/graph/load.go index 8f1da31136..c257e9ef16 100644 --- a/graph/load.go +++ b/graph/load.go @@ -104,6 +104,20 @@ func (s *TagStore) recursiveLoad(eng *engine.Engine, address, tmpImageDir string log.Debugf("Error validating ID: %s", err) return err } + + // ensure no two downloads of the same layer happen at the same time + if c, err := s.poolAdd("pull", "layer:"+img.ID); err != nil { + if c != nil { + log.Debugf("Image (id: %s) load is already running, waiting: %v", img.ID, err) + <-c + return nil + } + + return err + } + + defer s.poolRemove("pull", "layer:"+img.ID) + if img.Parent != "" { if !s.graph.Exists(img.Parent) { if err := s.recursiveLoad(eng, img.Parent, tmpImageDir); err != nil {