From 947519bfb31024ea8c76e8e303f2c338b00265f2 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Thu, 10 Sep 2015 14:58:06 -0700 Subject: [PATCH] Broadcaster writer goroutines must only finish when they are caught up Without this change, there was a narrow race condition that would allow writers to finish when there was still data left to write. This is likely to be what was causing some integration tests to fail with truncated pull output. Signed-off-by: Aaron Lehmann --- pkg/progressreader/broadcaster.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/progressreader/broadcaster.go b/pkg/progressreader/broadcaster.go index 429b1d0f1b..5118e9e2f8 100644 --- a/pkg/progressreader/broadcaster.go +++ b/pkg/progressreader/broadcaster.go @@ -77,6 +77,12 @@ func (broadcaster *Broadcaster) receiveWrites(observer io.Writer) { broadcaster.Lock() + // If we are behind, we need to catch up instead of waiting + // or handling a closure. + if len(broadcaster.history) != n { + continue + } + // detect closure of the broadcast writer if broadcaster.closed() { broadcaster.Unlock() @@ -84,9 +90,7 @@ func (broadcaster *Broadcaster) receiveWrites(observer io.Writer) { return } - if len(broadcaster.history) == n { - broadcaster.cond.Wait() - } + broadcaster.cond.Wait() // Mutex is still locked as the loop continues }