Skip to content

Commit

Permalink
increases client-side websocket write deadline to 30 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
seans3 committed Mar 2, 2024
1 parent f4b0115 commit 1d4be75
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions staging/src/k8s.io/client-go/tools/remotecommand/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1d4be75

Please sign in to comment.