From d0ba962c8df6ec3e426d17d9070850edcfbe944d Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Tue, 21 May 2024 09:09:49 -0700 Subject: [PATCH] fix: cli port-forward fails with high network latency (#4632) --- pkg/k8sutil/portforward.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/k8sutil/portforward.go b/pkg/k8sutil/portforward.go index b17b51a73f..dfc8030082 100644 --- a/pkg/k8sutil/portforward.go +++ b/pkg/k8sutil/portforward.go @@ -217,7 +217,7 @@ func PortForward(localPort int, remotePort int, namespace string, getPodName fun if err == nil && response.StatusCode == http.StatusOK { break } - if time.Now().Sub(start) > time.Duration(time.Second*10) { + if time.Since(start) > time.Duration(time.Second*10) { if err == nil { err = errors.Errorf("service responded with status %s", response.Status) } @@ -225,9 +225,7 @@ func PortForward(localPort int, remotePort int, namespace string, getPodName fun } time.Sleep(time.Millisecond * 100) - if quickClient.Timeout < time.Second { - quickClient.Timeout = quickClient.Timeout + time.Millisecond*100 - } + quickClient.Timeout *= 2 // 200ms, 400ms, 800ms, 1.6s, 3.2s, 6.4s } if pollForAdditionalPorts {