fix(stream): implement RFC 6455 WebSocket ping/pong heartbeats and TCP keepalive (#1841) #2807
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 314 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.344
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2807"
general
weight: 0.35
roycaihw
What type of PR is this?
/kind bug
What this PR does / why we need it:
Long-running streaming commands (
exec,attach, andport-forward) viastream()orportforward()can drop silently or raiseWebSocketConnectionClosedExceptionwhen passing through idle intermediate proxies, firewalls, or load balancers (such as AWS ALB, Envoy, or NGINX).This PR adds opt-in application-level RFC 6455 WebSocket
Pingheartbeats alongside TCP keepalive socket options inkubernetes/stream/:1. Opt-in Background Ping Worker (
WSClient): Acceptsping_intervalonWSClient,websocket_call(), andstream()(forwarded only when explicitly provided). Whenping_interval > 0(excluding booleans), a daemon thread sends periodic RFC 6455Pingcontrol frames viaself.sock.ping()untilclose(),run_forever()completion, or receivingABNF.OPCODE_CLOSE.2. Incoming Ping Handling Preserved Without Duplicates: Relies on
websocket-client'srecv_data_frame(True)automaticPongreply in bothWSClient.update()andPortForward._proxy()rather than sending a second pong frame.3. TCP Keepalive & Custom Socket Options (
create_websocket): Appliesconfiguration.socket_optionsif configured, ortcp_keepalive_socket_options()whenconfiguration.keep_alive is True. Keepingconfiguration.keep_alivescoped solely to TCP keepalive preserves existing behavior for callers unlessping_intervalis explicitly passed.4. Unit Tests: Covers opt-in
ping_intervalforwarding and validation, keepingkeep_alive=Truescoped to TCP keepalive, applying TCP/custom socket options increate_websocket, and asserting single-pong replies viamock_pong.assert_called_once_with(...)inWSClient.update()andPortForward._proxy().Which issue(s) this PR fixes:
Fixes #1841
Special notes for your reviewer:
Verified locally on Windows (Python 3.14) across
kubernetes/stream/stream_test.py,kubernetes/utils/keepalive_test.py, andWSClientPingPongTest/CreateWebsocketCaCertDataTest/ non-select.polltests inkubernetes/stream/ws_client_test.py.Does this PR introduce a user-facing change?
``
release-noteping_intervalAdded opt-in
support for WebSocketPingheartbeats instream()/WSClientand applied TCP keepalive (configuration.keep_alive) /configuration.socket_optionsincreate_websocket().docs
``