Fix AtomicWriteFile with an Open reader on Windows #1325
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.337
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1325"
general
weight: 0.35
mtrmac
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 whilepodman machine listis reading it [1].The problem is that, on Windows, Go
os.Renameuses the Win32 APIMoveFileEx(MOVEFILE_REPLACE_EXISTING)[2] that fails if the destination files has an open handle, even if it has been opened with the flagFILE_SHARE_DELETE[3].To address that we have implemented a POSIX rename function that calls
CreateFile[4], to open the temporary file, and thenSetInformationByHandle[5], with flagsFILE_RENAME_POSIX_SEMANTICSandFILE_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.Renamethough, and fall back toposixRenameonly if the first fails. This has two benefits:MoveFileExis more portable compared toSetInformationByHandle, it is supported on older versions of Windows.This commits doesn't fix [1] completely, because
podman machine lsstill reads the configuration file without theFILE_SHARE_DELETEflag. 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 --->