Skip to content

Commit f883f17

Browse files
fuweidk8s-publishing-bot
authored andcommitted
proxy: should add PingPeriod for websocket translator
IIUC, before using the translator handler, the ping data can be delivered from the client to the runtime side since kube-apiserver does not parse any client data. However, with WebSocket, the server responds with a pong to the client without forwarding the data to the runtime side. If a proxy is present, it may close the connection due to inactivity. SPDY's PingPeriod can help address this issue. Signed-off-by: Wei Fu <[email protected]> Co-authored-by: Antonio Ojea <[email protected]> (cherry picked from commit dc59c0246fb407dcf035afc224f63fcf0da8244e) Signed-off-by: Wei Fu <[email protected]> Kubernetes-commit: e8b0252a41295ad09e44f638dde9f76e1c0accf4
1 parent 6da0824 commit f883f17

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pkg/util/proxy/streamtranslator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
"net/url"
2323
"strconv"
24+
"time"
2425

2526
"github.com/mxk/go-flowrate/flowrate"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -70,7 +71,7 @@ func (h *StreamTranslatorHandler) ServeHTTP(w http.ResponseWriter, req *http.Req
7071
defer websocketStreams.conn.Close()
7172

7273
// Creating SPDY executor, ensuring redirects are not followed.
73-
spdyRoundTripper, err := spdy.NewRoundTripperWithConfig(spdy.RoundTripperConfig{UpgradeTransport: h.Transport})
74+
spdyRoundTripper, err := spdy.NewRoundTripperWithConfig(spdy.RoundTripperConfig{UpgradeTransport: h.Transport, PingPeriod: 5 * time.Second})
7475
if err != nil {
7576
websocketStreams.writeStatus(apierrors.NewInternalError(err)) //nolint:errcheck
7677
metrics.IncStreamTranslatorRequest(req.Context(), strconv.Itoa(http.StatusInternalServerError))

0 commit comments

Comments
 (0)