From 5fc16a826732e92e976197eac40c4106c1768d98 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 17 Jul 2015 14:08:51 +0100 Subject: [PATCH] [proxy] use a waitgroup as it's more semantically accurate --- proxy/proxy_intercept.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proxy/proxy_intercept.go b/proxy/proxy_intercept.go index 69f83c83..787ad6b0 100644 --- a/proxy/proxy_intercept.go +++ b/proxy/proxy_intercept.go @@ -9,6 +9,7 @@ import ( "net" "net/http" "net/http/httputil" + "sync" "github.com/fsouza/go-dockerclient" . "github.com/weaveworks/weave/common" @@ -94,16 +95,15 @@ func doRawStream(w http.ResponseWriter, resp *http.Response, client *httputil.Cl return } - upDone := make(chan struct{}) - downDone := make(chan struct{}) - go copyStream(down, io.MultiReader(rem, up), upDone) - go copyStream(up, downBuf, downDone) - <-upDone - <-downDone + var wg sync.WaitGroup + wg.Add(2) + go copyStream(down, io.MultiReader(rem, up), &wg) + go copyStream(up, downBuf, &wg) + wg.Wait() } -func copyStream(dst io.Writer, src io.Reader, done chan struct{}) { - defer close(done) +func copyStream(dst io.Writer, src io.Reader, wg *sync.WaitGroup) { + defer wg.Done() if _, err := io.Copy(dst, src); err != nil { Warning.Print(err) }