From f759d2e9764cf6b7d87fea3b63df8d1233c84890 Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Fri, 1 Mar 2024 18:16:44 -0800 Subject: [PATCH] increases client-side websocket write deadline to 30 seconds Kubernetes-commit: 1d4be7527f8b2d2c4eb6dcc7ef58b4c3133f6f19 --- tools/remotecommand/websocket.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/remotecommand/websocket.go b/tools/remotecommand/websocket.go index 49ef4717..e6e893a1 100644 --- a/tools/remotecommand/websocket.go +++ b/tools/remotecommand/websocket.go @@ -36,13 +36,9 @@ import ( "k8s.io/klog/v2" ) -// writeDeadline defines the time that a write to the websocket connection -// must complete by, otherwise an i/o timeout occurs. The writeDeadline -// has nothing to do with a response from the other websocket connection -// endpoint; only that the message was successfully processed by the -// local websocket connection. The typical write deadline within the websocket -// library is one second. -const writeDeadline = 2 * time.Second +// writeDeadline defines the time that a client-side write to the websocket +// connection must complete before an i/o timeout occurs. +const writeDeadline = 30 * time.Second var ( _ Executor = &wsStreamExecutor{} @@ -65,8 +61,8 @@ const ( // "pong" message before a timeout error occurs for websocket reading. // This duration must always be greater than the "pingPeriod". By defining // this deadline in terms of the ping period, we are essentially saying - // we can drop "X-1" (e.g. 3-1=2) pings before firing the timeout. - pingReadDeadline = (pingPeriod * 3) + (1 * time.Second) + // we can drop "X-1" (e.g. 6-1=5) pings before firing the timeout. + pingReadDeadline = (pingPeriod * 6) + (1 * time.Second) ) // wsStreamExecutor handles transporting standard shell streams over an httpstream connection. @@ -497,7 +493,7 @@ func (h *heartbeat) start() { // "WriteControl" does not need to be protected by a mutex. According to // gorilla/websockets library docs: "The Close and WriteControl methods can // be called concurrently with all other methods." - if err := h.conn.WriteControl(gwebsocket.PingMessage, h.message, time.Now().Add(writeDeadline)); err == nil { + if err := h.conn.WriteControl(gwebsocket.PingMessage, h.message, time.Now().Add(pingReadDeadline)); err == nil { klog.V(8).Infof("Websocket Ping succeeeded") } else { klog.Errorf("Websocket Ping failed: %v", err)