From e0a6887babba56e6c5f686e476908ea992b55521 Mon Sep 17 00:00:00 2001 From: Andriy Dzikh Date: Thu, 29 Apr 2021 10:08:49 -0700 Subject: [PATCH] Add message saying when download is waiting for a file lock. --- pkg/minikube/download/download.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/download/download.go b/pkg/minikube/download/download.go index b606f4539a..e6b37d0866 100644 --- a/pkg/minikube/download/download.go +++ b/pkg/minikube/download/download.go @@ -22,12 +22,14 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/hashicorp/go-getter" "github.com/juju/mutex" "github.com/pkg/errors" "k8s.io/klog/v2" "k8s.io/minikube/pkg/minikube/out" + "k8s.io/minikube/pkg/minikube/style" "k8s.io/minikube/pkg/util/lock" ) @@ -96,10 +98,29 @@ func withinUnitTest() bool { } func lockDownload(file string) (mutex.Releaser, error) { - spec := lock.PathMutexSpec(file) - releaser, err := mutex.Acquire(spec) - if err != nil { - return nil, errors.Wrapf(err, "failed to acquire lock \"%s\": %+v", file, spec) + type retPair struct { + mutex.Releaser + error } - return releaser, err + lockChannel := make(chan retPair) + + go func() { + spec := lock.PathMutexSpec(file) + releaser, err := mutex.Acquire(spec) + if err != nil { + lockChannel <- retPair{nil, errors.Wrapf(err, "failed to acquire lock \"%s\": %+v", file, spec)} + return + } + lockChannel <- retPair{releaser, err} + }() + + select { + case r := <-lockChannel: + return r.Releaser, r.error + case <-time.After(time.Millisecond * 100): + out.Step(style.Waiting, "Another minikube instance is downloading dependencies...") + } + + r := <-lockChannel + return r.Releaser, r.error }