fix: add 20s timeout to driver.Status()

pull/17553/head
Raiden Shogun 2023-11-04 23:38:52 +01:00
parent 12f5db0553
commit 61b69e13f8
2 changed files with 31 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import (
"sort"
"strconv"
"strings"
"time"
"golang.org/x/text/cases"
"golang.org/x/text/language"
@ -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.

View File

@ -20,6 +20,7 @@ import (
"fmt"
"os"
"sort"
"time"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/translate"
@ -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