Skip to content

Commit

Permalink
Use the config client_idle_timeout instead of a hardcoded value to al…
Browse files Browse the repository at this point in the history
…low for long-running fort forard / exec sessions. (#49430)
  • Loading branch information
creack authored Nov 26, 2024
1 parent 2a107d8 commit 341482a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/kube/proxy/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const (

// DefaultStreamCreationTimeout
DefaultStreamCreationTimeout = 30 * time.Second

IdleTimeout = 15 * time.Minute
)

// These constants are for remote command execution and port forwarding and are
Expand Down
2 changes: 2 additions & 0 deletions lib/kube/proxy/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,7 @@ func (f *Forwarder) exec(authCtx *authContext, w http.ResponseWriter, req *http.
httpResponseWriter: w,
context: ctx,
pingPeriod: f.cfg.ConnPingPeriod,
idleTimeout: sess.clientIdleTimeout,
onResize: func(remotecommand.TerminalSize) {},
}

Expand Down Expand Up @@ -1782,6 +1783,7 @@ func (f *Forwarder) portForward(authCtx *authContext, w http.ResponseWriter, req
onPortForward: onPortForward,
targetDialer: dialer,
pingPeriod: f.cfg.ConnPingPeriod,
idleTimeout: sess.clientIdleTimeout,
}
f.log.Debugf("Starting %v.", request)
err = runPortForwarding(request)
Expand Down
7 changes: 5 additions & 2 deletions lib/kube/proxy/portforward_spdy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type portForwardRequest struct {
context context.Context
targetDialer httpstream.Dialer
pingPeriod time.Duration
idleTimeout time.Duration
}

func (p portForwardRequest) String() string {
Expand Down Expand Up @@ -103,8 +104,10 @@ func runPortForwardingHTTPStreams(req portForwardRequest) error {
targetConn: targetConn,
}
defer h.Close()
h.Debugf("Setting port forwarding streaming connection idle timeout to %v", IdleTimeout)
conn.SetIdleTimeout(IdleTimeout)

h.Debugf("Setting port forwarding streaming connection idle timeout to %s.", req.idleTimeout)
conn.SetIdleTimeout(req.idleTimeout)

h.run()
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion lib/kube/proxy/portforward_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func runPortForwardingWebSocket(req portForwardRequest) error {
Channels: channels,
},
})
conn.SetIdleTimeout(IdleTimeout)

conn.SetIdleTimeout(req.idleTimeout)

// Upgrade the request and create the virtual streams.
_, streams, err := conn.Open(
Expand Down
3 changes: 2 additions & 1 deletion lib/kube/proxy/remotecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type remoteCommandRequest struct {
onResize resizeCallback
context context.Context
pingPeriod time.Duration
idleTimeout time.Duration
}

func (req remoteCommandRequest) eventPodMeta(ctx context.Context, creds kubeCreds) apievents.KubernetesPodMetadata {
Expand Down Expand Up @@ -153,7 +154,7 @@ func createSPDYStreams(req remoteCommandRequest) (*remoteCommandProxy, error) {
return nil, trace.ConnectionProblem(trace.BadParameter("missing connection"), "missing connection")
}

conn.SetIdleTimeout(IdleTimeout)
conn.SetIdleTimeout(req.idleTimeout)

var handler protocolHandler
switch protocol {
Expand Down
4 changes: 3 additions & 1 deletion lib/kube/proxy/remotecommand_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func createWebSocketStreams(req remoteCommandRequest) (*remoteCommandProxy, erro
Channels: channels,
},
})
conn.SetIdleTimeout(IdleTimeout)

conn.SetIdleTimeout(req.idleTimeout)

negotiatedProtocol, streams, err := conn.Open(
responsewriter.GetOriginal(req.httpResponseWriter),
req.httpRequest,
Expand Down

0 comments on commit 341482a

Please sign in to comment.