Prevent 2 goroutines from being leaked if proxy hangs

Signed-off-by: Ziheng Liu <lzhfromustc@gmail.com>
This commit is contained in:
Ziheng Liu 2019-10-28 19:06:43 -04:00
parent b6c8f4916d
commit 2ca513a15d
2 changed files with 3 additions and 5 deletions

View File

@ -89,10 +89,9 @@ type RuntimeOperationErrorRate struct {
// ProxyRequest performs a get on a node proxy endpoint given the nodename and rest client.
func ProxyRequest(c clientset.Interface, node, endpoint string, port int) (restclient.Result, error) {
// proxy tends to hang in some cases when Node is not ready. Add an artificial timeout for this call.
// This will leak a goroutine if proxy hangs. #22165
// proxy tends to hang in some cases when Node is not ready. Add an artificial timeout for this call. #22165
var result restclient.Result
finished := make(chan struct{})
finished := make(chan struct{}, 1)
go func() {
result = c.CoreV1().RESTClient().Get().
Resource("nodes").

View File

@ -76,8 +76,7 @@ func parseKubeletMetrics(data string) (KubeletMetrics, error) {
func (g *Grabber) getMetricsFromNode(nodeName string, kubeletPort int) (string, error) {
// There's a problem with timing out during proxy. Wrapping this in a goroutine to prevent deadlock.
// Hanging goroutine will be leaked.
finished := make(chan struct{})
finished := make(chan struct{}, 1)
var err error
var rawOutput []byte
go func() {