From e1ae906048003145441fb1d4ecce4c13acf5cb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Tue, 3 Oct 2023 12:05:26 +0300 Subject: [PATCH] Close websocket heartbeat explicitly when unexpected closure received --- .../client-go/tools/remotecommand/websocket.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go b/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go index 9230027c039..78de8af1aac 100644 --- a/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go +++ b/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go @@ -18,8 +18,10 @@ package remotecommand import ( "context" + "errors" "fmt" "io" + "net" "net/http" "sync" "time" @@ -476,9 +478,15 @@ func (h *heartbeat) start() { klog.V(8).Infof("Websocket Ping succeeeded") } else { klog.Errorf("Websocket Ping failed: %v", err) - // Continue, in case this is a transient failure. - // c.conn.CloseChan above will tell us when the connection is - // actually closed. + if errors.Is(err, gwebsocket.ErrCloseSent) { + continue + } else if e, ok := err.(net.Error); ok && e.Temporary() { + // Continue, in case this is a transient failure. + // c.conn.CloseChan above will tell us when the connection is + // actually closed. + continue + } + return } } }