← Back to Pull requests

exec/attach: let the client close the connection so no output is lost #142461

Open
unknown opened this pull request with 357 lines diff across 4 files
View on GitHub
unknown unknown commented on Sep 27, 2026 21:50 UTC
Author

Draft. The client-go part is now #142712 and the translator part #143324; this PR will be cut down to the cri-streaming change on top of them, which waits for the KEP discussed in #142376.

What type of PR is this?

/kind bug

What this PR does / why we need it:

kubectl exec and attach lose the end of the output when the client reads more slowly than the command writes and is also sending input (#142376). The server writes the status and closes the connection at once; the client's next frame then makes the kernel reset the connection and drop what is still in the send buffer. Over SPDY, client-go then sees an empty status and reports success.

The change:

  • The CRI streaming server (k8s.io/cri-streaming) and the WebSocket translator no longer close first. They send the status, signal the end (SPDY: close the output streams; WebSocket: a close frame, new wsstream.Conn.CloseWrite), and wait for the client to close, bounded by the request context and 15 minutes.

  • client-go treats an empty status stream on v4/v5 as an error (connection closed before the command's status was received) instead of success.
  • Behaviour change: a client that neither closes nor answers the close frame now holds the session for up to 15 minutes after the command exits (the old code returned at once).

    Tested with unit tests that reproduce the loss on the old code, and on a real multi-node cluster with containerd, CRI-O and Windows; results in https://github.com/kubernetes/kubernetes/pull/142461#issuecomment-5920263856.

    Which issue(s) this PR is related to:

    Part of #142376

    Related: #60140, #124571

    Special notes for your reviewer:

    Reading order: finish in cri-streaming/pkg/streaming/remotecommand/httpstream.go, CloseWrite/CloseChan in streaming/pkg/httpstream/wsstream/conn.go, the translator in apiserver/pkg/util/proxy, the client-go check in tools/remotecommand. The runtimes vendor the server, so they need a bump or port after this merges (plan in #142376).

    Credits: the report and first reproduction are @knoppiks's; @herefindalex isolated the close sequence; @thc1006 reproduced it on four nodes and found the mixed-version case in review.

    Does this PR introduce a user-facing change?

    ``release-note
    Fixed
    kubectl exec, kubectl attach and crictl exec losing the end of the output when the client read more slowly than the command wrote; over SPDY kubectl exec could also exit 0 with truncated output. The CRI streaming server and the WebSocket translator now wait up to 15 minutes for the client to close the connection after the command exits, and client-go reports an error when the command's status is missing.
    ``

    AI usage disclosure:

    YES. Used to check the diagnosis and fix against the source (a second pass after my own), and to help draft and format this description.

    Diff: 357 lines (+267 / -90) across 4 files Reviewer: semx Review duration: 92175m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 357 lines diff across 4 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.352
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #142461"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.6% (MEDIUM) · Higher = larger blast radius
    49.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.4% · Safe to merge
    27.4%