← Back to Pull requests

Fix AtomicWriteFile with an Open reader on Windows #1325

Closed
unknown closed this pull request without merging on Nov 05, 2026 17:48 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 14:01 UTC
Author

On Windows, AtomicWriteFile fails with "Access is denied" when another process has the destination file open. For example, podman machine start, fails to update the machine config while podman machine list is reading it [1].

The problem is that, on Windows, Go os.Rename uses the Win32 API MoveFileEx(MOVEFILE_REPLACE_EXISTING) [2] that fails if the destination files has an open handle, even if it has been opened with the flag FILE_SHARE_DELETE [3].

To address that we have implemented a POSIX rename function that calls CreateFile [4], to open the temporary file, and then SetInformationByHandle [5], with flags FILE_RENAME_POSIX_SEMANTICS and FILE_RENAME_REPLACE_IF_EXISTS [6], to rename the file.

Note that, in this case, replacing the file still needs a DELETE access to it, so readers must have opened it with FILE_SHARE_DELETE.

We are still using Go os.Rename though, and fall back to posixRename only if the first fails. This has two benefits:

  • MoveFileEx is more portable compared to SetInformationByHandle, it is supported on older versions of Windows.

  • If another process holds an exclusive delete access handle, trying it a second time, gives us a chance that the handle has been released and renaming succeeds.
  • This commits doesn't fix [1] completely, because podman machine ls still reads the configuration file without the FILE_SHARE_DELETE flag. But it mitigates it, because of the retry. Another commit, Podman side, is needed to fix it definitely.

    [1] https://github.com/podman-container-tools/podman/issues/28873
    [2] https://github.com/golang/go/blob/go1.27.0/src/internal/syscall/windows/syscall_windows.go
    [3] https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexw
    [4] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew
    [5] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle
    [6] https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information

    <!--- Please read the contributing guidelines before proceeding --->

    Diff: 277 lines (+207 / -70) across 3 files Reviewer: mtrmac Review duration: 227m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 277 lines diff across 3 files
    0.40
    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.337
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1325"
    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: 39.6% (MEDIUM) · Higher = larger blast radius
    39.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: 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: 15.6% · Safe to merge
    15.6%