From fdef567da603d26eb2b348e23a2636b9991c7188 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 7 Aug 2019 17:39:09 +0100 Subject: [PATCH] cmd: shorten the locking window when using --progress to avoid deadlock Before this change, using -P occasionally deadlocked on the progress mutex and the stats mutex since they call each other. This is fixed by shortening the locking window in the progress routine so as not to include the stats calculation. --- cmd/progress.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/progress.go b/cmd/progress.go index 0ea44501a..8c09cee89 100644 --- a/cmd/progress.go +++ b/cmd/progress.go @@ -84,9 +84,6 @@ var ( // printProgress prints the progress with an optional log func printProgress(logMessage string) { - progressMu.Lock() - defer progressMu.Unlock() - var buf bytes.Buffer w, h, err := terminal.GetSize(int(os.Stdout.Fd())) if err != nil { @@ -100,6 +97,10 @@ func printProgress(logMessage string) { buf.WriteString(s) } + // Lock from here to prevent terminal corruption + progressMu.Lock() + progressMu.Unlock() + if logMessage != "" { out("\n") out(moveUp)