← Back to Pull requests

shim: don't tear down shared pod UVM on Hyper-V container restart #2846

Closed
unknown closed this pull request without merging on Nov 20, 2026 22:19 UTC
View on GitHub
unknown unknown commented on Jul 30, 2026 18:14 UTC
Author

Description

Fix in-place container restarts for Hyper-V isolated Windows pods (runhcs-wcow-hypervisor), e.g. with ContainerRestartRules / RestartAllContainers. Today a workload container restart can tear down the shared pod UVM, killing the sandbox and every other container in the pod. This is the failure reported in kubernetes/kubernetes#140187.

Root cause

A Windows guest holds the WaitForProcess response of a process until the host closes the process's stdio relay. A descendant process (for example the child of sh -c "...; sleep ...") can keep the relay open after the process itself has exited, while the host only closes the relay once the wait completes, so neither side makes progress. The SIGKILL that follows returns hrNotFound, which was logged and ignored, leaving the wait pending. The 30s SIGKILL watchdog in KillExec then closed the UVM, even when the task did not own it.

Fix

1. Gate the KillExec SIGKILL watchdog on ownsHost, so only a task that owns its UVM can close it. A workload container shares the pod UVM.
2. When a Windows guest reports a process missing while its wait is still pending, wait a grace period for the real exit, then close the host side of the process's stdio relay. The guest then delivers the real exit code; no exit is synthesized and the bridge protocol is unchanged. The grace period (1s) matches the default CopyAfterExitTimeout the host already allows stdio relays after a process exits, and the path is only taken on the abnormal hrNotFound path.

Linux guests (LCOW) are excluded: they drain and close the relay themselves before answering the wait, and reconnect if the host closes it first. Process-isolated containers don't use this code path.

Testing

  • go test ./internal/gcs ./cmd/containerd-shim-runhcs-v1, including new tests that:

  • - the real exit code is kept and stdio stays open when the real exit arrives within the grace period;
    - stdio is closed to release the real exit when the guest holds it;
    - a Linux guest's stdio relay is never closed.
  • On a CAPZ Hyper-V cluster, ran the four RestartAllContainers e2e specs that fail today 10 times each: 40/40 passed (0/4 before). With ETW (ContainerPlatform) traces: no watchdog, no UVM close/terminate during the tests; every hrNotFound was followed by the stdio close after ~1s and the real exit (0xC000013A) within a few ms, which containerd reported as the container's exit status.

  • 24 direct CRI stop probes on Hyper-V pods (sh -c with a child, sh -c with redirect / exec, direct process, grace 0/2): sandbox and sibling containers stayed running and the UVM was not closed in every case; real exit codes were reported.
  • Diff: 337 lines (+252 / -85) across 4 files Reviewer: rzlink Review duration: 162964m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 337 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2846"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 16.7% · Safe to merge
    16.7%