Skip to content

Commit

Permalink
fix: add 20s timeout to driver.Status()
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Nov 4, 2023
1 parent 12f5db0 commit 61b69e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
24 changes: 19 additions & 5 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand Down Expand Up @@ -354,12 +355,25 @@ func Suggest(options []registry.DriverState) (registry.DriverState, []registry.D
// Status returns the status of a driver
func Status(name string) registry.DriverState {
d := registry.Driver(name)
return registry.DriverState{
Name: d.Name,
Default: d.Default,
Priority: d.Priority,
State: registry.Status(name),
stateChannel := make(chan registry.State)
timeoutChannel := time.After(20 * time.Second)
go func() {
stateChannel <- registry.Status(name)
}()
select {
case s := <-stateChannel:
return registry.DriverState{
Name: d.Name,
Default: d.Default,
Priority: d.Priority,
State: s,
}
case <-timeoutChannel:
klog.Infof("time out when checking for status of %s driver", name)
return registry.DriverState{}

}

}

// IsAlias checks if an alias belongs to provided driver by name.
Expand Down
13 changes: 12 additions & 1 deletion pkg/minikube/registry/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"sort"
"time"

"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/translate"
Expand Down Expand Up @@ -118,7 +119,17 @@ func Available(vm bool) []DriverState {
klog.Errorf("%q does not implement Status", d.Name)
continue
}
s := d.Status()
stateChannel := make(chan State)
timeoutChannel := time.After(20 * time.Second)
go func() {
stateChannel <- d.Status()
}()
s := State{}
select {
case <-timeoutChannel:
klog.Infof("%s status check timeout!", d.Name)
case s = <-stateChannel:
}
klog.Infof("%s default: %v priority: %d, state: %+v", d.Name, d.Default, d.Priority, s)

preference := d.Priority
Expand Down

0 comments on commit 61b69e1

Please sign in to comment.