Explorar el Código

Remove io.Pipe used for download progress

The original purpose of this was to cancel downloads if pullV2Tag
returns an error, preventing an associated crash (see #15353). The
broadcaster now accomplishes the same thing that the pipe does, making
the pipe redundant. When pullV2Tag returns, all broadcasters are closed,
which means all further writes to those broadcasters will return errors.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann hace 9 años
padre
commit
50c355777e
Se han modificado 1 ficheros con 1 adiciones y 29 borrados
  1. 1 29
      graph/pull_v2.go

+ 1 - 29
graph/pull_v2.go

@@ -1,7 +1,6 @@
 package graph
 package graph
 
 
 import (
 import (
-	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
@@ -193,33 +192,6 @@ func (p *v2Puller) pullV2Tag(out io.Writer, tag, taggedName string) (verified bo
 		logrus.Printf("Image manifest for %s has been verified", taggedName)
 		logrus.Printf("Image manifest for %s has been verified", taggedName)
 	}
 	}
 
 
-	// By using a pipeWriter for each of the downloads to write their progress
-	// to, we can avoid an issue where this function returns an error but
-	// leaves behind running download goroutines. By splitting the writer
-	// with a pipe, we can close the pipe if there is any error, consequently
-	// causing each download to cancel due to an error writing to this pipe.
-	pipeReader, pipeWriter := io.Pipe()
-	go func() {
-		if _, err := io.Copy(out, pipeReader); err != nil {
-			logrus.Errorf("error copying from layer download progress reader: %s", err)
-			if err := pipeReader.CloseWithError(err); err != nil {
-				logrus.Errorf("error closing the progress reader: %s", err)
-			}
-		}
-	}()
-	defer func() {
-		if err != nil {
-			// All operations on the pipe are synchronous. This call will wait
-			// until all current readers/writers are done using the pipe then
-			// set the error. All successive reads/writes will return with this
-			// error.
-			pipeWriter.CloseWithError(errors.New("download canceled"))
-		} else {
-			// If no error then just close the pipe.
-			pipeWriter.Close()
-		}
-	}()
-
 	out.Write(p.sf.FormatStatus(tag, "Pulling from %s", p.repo.Name()))
 	out.Write(p.sf.FormatStatus(tag, "Pulling from %s", p.repo.Name()))
 
 
 	var downloads []*downloadInfo
 	var downloads []*downloadInfo
@@ -275,7 +247,7 @@ func (p *v2Puller) pullV2Tag(out io.Writer, tag, taggedName string) (verified bo
 		downloads = append(downloads, d)
 		downloads = append(downloads, d)
 
 
 		broadcaster, found := p.poolAdd("pull", d.poolKey)
 		broadcaster, found := p.poolAdd("pull", d.poolKey)
-		broadcaster.Add(pipeWriter)
+		broadcaster.Add(out)
 		d.broadcaster = broadcaster
 		d.broadcaster = broadcaster
 		if found {
 		if found {
 			d.err <- nil
 			d.err <- nil