← Back to Pull requests

bindings: stop mutating shared HTTP transport in exec attach #30421

Open
Elvand-Lie opened this pull request with 205 lines diff across 4 files
View on GitHub
Elvand-Lie Elvand-Lie commented on Dec 03, 2026 09:17 UTC
Author

What this PR does

Fixes two issues in containers.ExecStartAndAttach:

1. Avoids mutating the shared HTTP transport: Previously, attach.go permanently swapped the client's shared HTTP transport without a lock (noted in an existing FIXME), breaking concurrent attach calls. This change uses an httptrace.ClientTrace GotConn hook to capture the underlying attach socket while leaving the shared transport untouched.
2. Adds DisableLocalTerminal option: Even when a caller passes their own InputStream, attach.go still hard-codes os.Stdin for terminal checks, raw mode (when os.Stdin is a terminal and the exec session has a TTY), and resize handling. The new opt-in DisableLocalTerminal option skips this local terminal handling and leaves the caller's terminal untouched.
3. Aligns the exec start Tty field: The exec start request's Tty field now follows the exec session's own TTY setting rather than the local terminal check.

Testing

  • Added a regression test that does not compile on main as written (due to WithDisableLocalTerminal), and fails on main with "replaced the shared HTTP transport" if that option call is removed.

  • Verified the new test passes with -race, both standalone and across the full bindings/containers package.
  • Fixes: #25090

    <!-- Thanks for sending a pull request! -->

    Checklist

    Ensure you have completed the following checklist for your pull request to be reviewed:
    <!-- Use [x] to mark as done, or click the checkbox after opening PR -->

  • I have read and understood our contributing guidelines and will not have more than two open PRs as a new contributor.

  • PR description, commit message, and GitHub comments are human-written, per LLM Policy

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by including your Signed-off-by line in all

  • commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. Read the DCO Sign-off requirements
    and ensure you follow them before signing off your commits.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)

  • Tests have been added/updated (or no tests are needed)

  • Documentation has been updated (or no documentation changes are needed)

  • All commits pass make validatepr (format/lint checks)

  • Release note entered in the section below (or None if no user-facing changes)
  • Does this PR introduce a user-facing change?

    <!--
    Write None if there are no user-facing changes, otherwise enter your release note below.
    Include "action required" if users need to take action when upgrading.
    -->

    ``release-note
    Fixed a race condition in the Go bindings where
    ExecStartAndAttach mutated the shared HTTP transport, and added a DisableLocalTerminal option to skip local os.Stdin terminal handling.
    ``

    Diff: 205 lines (+151 / -54) across 4 files Reviewer: mheon Review duration: 1557m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.39) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 205 lines diff across 4 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 3 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    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.319
    Real PR Conversation Timeline
    4 items
    Honny1 Honny1 commented on Dec 03, 2026 16:40 UTC
    Contributor

    @mheon

    mheon mheon commented on code on Dec 03, 2026 21:33 UTC
    Code Review
    pkg/bindings/containers/types.go:1
    @@ -319,6 +319,9 @@ type ExecStartAndAttachOptions struct {
     	// AttachInput is whether to attach to STDIN
     	// If false, stdout will not be attached
     	AttachInput *bool
    +	// DisableLocalTerminal skips local raw mode and resize forwarding.

    Instead of this, should we not have the caller pass in the streams to use for STDOUT and STDIN?

    mheon mheon commented on code on Dec 03, 2026 21:33 UTC
    Code Review
    pkg/bindings/containers/attach.go:1
    @@ -450,7 +449,7 @@ func ExecStartAndAttach(ctx context.Context, sessionID string, options *ExecStar
     		Width  uint16 `json:"w"`
     	}{
     		Detach: false,
    -		TTY:    needTTY,
    +		TTY:    isTerm,

    Why was this swapped?

    Reviewers
    Assignees
    Elvand-Lie Elvand-Lie
    Labels
    risk: low confidence: 89.1% 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: 39.3% (MEDIUM) · Higher = larger blast radius
    39.3%
    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: 89.1% · Lower = rushed or shallow review
    89.1%
    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: 4.3% · Safe to merge
    4.3%